-
-
Notifications
You must be signed in to change notification settings - Fork 912
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document how to use a mocked notifier inside tests (#3367)
- Loading branch information
1 parent
42bfe81
commit 2e27da7
Showing
2 changed files
with
31 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// ignore_for_file: unused_local_variable | ||
|
||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import 'create_container.dart'; | ||
import 'notifier_mock/codegen.dart'; | ||
|
||
/* SNIPPET START */ | ||
void main() { | ||
test('Some description', () { | ||
final container = createContainer( | ||
// Override the provider to have it create our mock Notifier. | ||
overrides: [myNotifierProvider.overrideWith(MyNotifierMock.new)], | ||
); | ||
|
||
// Then obtain the mocked notifier through the container: | ||
final notifier = container.read(myNotifierProvider.notifier); | ||
|
||
// You can then interact with the notifier as you would with the real one: | ||
notifier.state = 42; | ||
}); | ||
} |