Skip to content

Commit

Permalink
Test throwing inside constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
rrousselGit committed Nov 13, 2023
1 parent aacc03c commit 449e445
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ void main() {

for (final factory in matrix()) {
group(factory.label, () {
test('Cannot share a Notifier instance between providers ', () {
final container = createContainer();
final notifier = factory.notifier((ref) => 0);

final provider = factory.provider<AsyncTestNotifierBase<int>, int>(
() => notifier,
);
final provider2 = factory.provider<AsyncTestNotifierBase<int>, int>(
() => notifier,
);

container.read(provider);

expect(
container.read(provider2),
isA<AsyncError<int>>(),
);
});

test('Can read state inside onDispose', () {
final container = createContainer();
late AsyncTestNotifierBase<int> notifier;
Expand Down
19 changes: 19 additions & 0 deletions packages/riverpod/test/providers/notifier/notifier_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ void main() {

for (final factory in matrix()) {
group(factory.label, () {
test('Cannot share a Notifier instance between providers ', () {
final container = createContainer();
final notifier = factory.notifier((ref) => 0);

final provider = factory.provider<TestNotifierBase<int>, int>(
() => notifier,
);
final provider2 = factory.provider<TestNotifierBase<int>, int>(
() => notifier,
);

container.read(provider);

expect(
() => container.read(provider2),
throwsA(isA<StateError>()),
);
});

test('Can read state inside onDispose', () {
final container = createContainer();
late TestNotifierBase<int> notifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ void main() {

for (final factory in matrix()) {
group(factory.label, () {
test('Cannot share a Notifier instance between providers ', () {
final container = createContainer();
final notifier = factory.notifier((ref) => Stream.value(0));

final provider = factory.provider<StreamTestNotifierBase<int>, int>(
() => notifier,
);
final provider2 = factory.provider<StreamTestNotifierBase<int>, int>(
() => notifier,
);

container.read(provider);

expect(
container.read(provider2),
isA<AsyncError<int>>(),
);
});

test('Can read state inside onDispose', () {
final container = createContainer();
late StreamTestNotifierBase<int> notifier;
Expand Down

0 comments on commit 449e445

Please sign in to comment.