Skip to content

Commit

Permalink
Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rrousselGit committed Mar 14, 2024
1 parent 597da1f commit c31e913
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
6 changes: 0 additions & 6 deletions packages/riverpod/lib/src/core/modifiers/select.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ class _ProviderSelector<InputT, OutputT> with ProviderListenable<OutputT> {
try {
return switch (value) {
ResultData(:final state) => Result.data(selector(state)),
// TODO test
ResultError(:final error, :final stackTrace) =>
Result.error(error, stackTrace),
};
} catch (err, stack) {
// TODO test
return Result.error(err, stack);
} finally {
if (kDebugMode) _debugIsRunningSelector = false;
Expand All @@ -68,14 +66,10 @@ class _ProviderSelector<InputT, OutputT> with ProviderListenable<OutputT> {
if (!lastSelectedValue.hasState ||
!newSelectedValue.hasState ||
lastSelectedValue.requireState != newSelectedValue.requireState) {
// TODO test events after selector exception correctly send `previous`s

onChange(newSelectedValue);
// TODO test handle exception in listener
switch (newSelectedValue) {
case ResultData(:final state):
listener(
// TODO test from error
lastSelectedValue.stateOrNull,
state,
);
Expand Down
27 changes: 27 additions & 0 deletions packages/riverpod/test/new/core/select_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:riverpod/riverpod.dart';
import 'package:test/test.dart';

void main() {
group('provider.select', () {
test('handles when the selector throws', () {
final provider = Provider((ref) => Object());
final container = ProviderContainer.test();

final errors = <Object>[];
container.read(provider);
final sub = container.listen(
provider.select((value) => throw StateError('Foo')),
(_, __) {},
onError: (err, stack) => errors.add(err),
);

container.invalidate(provider);

expect(
sub.read,
throwsA(isStateError.having((e) => e.message, 'message', 'Foo')),
);
expect(errors, [isStateError.having((e) => e.message, 'message', 'Foo')]);
});
});
}

0 comments on commit c31e913

Please sign in to comment.