-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add invalidatableFuture side effect (#19)
Fixes #18
- Loading branch information
1 parent
c0e571e
commit 7ae2d06
Showing
4 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'package:rearch/rearch.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'util.dart'; | ||
|
||
void main() { | ||
test('invalidatableFuture', () async { | ||
var shouldError = false; | ||
|
||
(AsyncValue<int> Function(), void Function()) testCapsule( | ||
CapsuleHandle use, | ||
) { | ||
return use.invalidatableFuture(() async { | ||
if (shouldError) throw Exception(); | ||
return 0; | ||
}); | ||
} | ||
|
||
final container = useContainer(); | ||
final (getState, invalidate) = container.read(testCapsule); | ||
|
||
expect(getState(), equals(const AsyncLoading(None<int>()))); | ||
await Future.delayed(Duration.zero, () => null); | ||
expect(getState(), equals(const AsyncData(0))); | ||
|
||
shouldError = true; | ||
invalidate(); | ||
|
||
expect(getState(), equals(const AsyncLoading(Some(0)))); | ||
await Future.delayed(Duration.zero, () => null); | ||
expect(getState(), isA<AsyncError<int>>); | ||
expect(getState().data, equals(const Some(0))); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'package:rearch/rearch.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
CapsuleContainer useContainer() { | ||
final container = CapsuleContainer(); | ||
addTearDown(container.dispose); | ||
return container; | ||
} |