diff --git a/packages/riverpod/test/providers/async_notifier/async_notifier_test.dart b/packages/riverpod/test/providers/async_notifier/async_notifier_test.dart index e9bb487a3..c1689759b 100644 --- a/packages/riverpod/test/providers/async_notifier/async_notifier_test.dart +++ b/packages/riverpod/test/providers/async_notifier/async_notifier_test.dart @@ -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, int>( + () => notifier, + ); + final provider2 = factory.provider, int>( + () => notifier, + ); + + container.read(provider); + + expect( + container.read(provider2), + isA>(), + ); + }); + test('Can read state inside onDispose', () { final container = createContainer(); late AsyncTestNotifierBase notifier; diff --git a/packages/riverpod/test/providers/notifier/notifier_test.dart b/packages/riverpod/test/providers/notifier/notifier_test.dart index 7a067faa4..20f35c6ac 100644 --- a/packages/riverpod/test/providers/notifier/notifier_test.dart +++ b/packages/riverpod/test/providers/notifier/notifier_test.dart @@ -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, int>( + () => notifier, + ); + final provider2 = factory.provider, int>( + () => notifier, + ); + + container.read(provider); + + expect( + () => container.read(provider2), + throwsA(isA()), + ); + }); + test('Can read state inside onDispose', () { final container = createContainer(); late TestNotifierBase notifier; diff --git a/packages/riverpod/test/providers/stream_notifier/async_notifier_test.dart b/packages/riverpod/test/providers/stream_notifier/async_notifier_test.dart index 95c21ca4a..d72fa124a 100644 --- a/packages/riverpod/test/providers/stream_notifier/async_notifier_test.dart +++ b/packages/riverpod/test/providers/stream_notifier/async_notifier_test.dart @@ -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, int>( + () => notifier, + ); + final provider2 = factory.provider, int>( + () => notifier, + ); + + container.read(provider); + + expect( + container.read(provider2), + isA>(), + ); + }); + test('Can read state inside onDispose', () { final container = createContainer(); late StreamTestNotifierBase notifier;