From 449e445fc0bfc13fa1c57a40c5ae6f846670dcd2 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 13 Nov 2023 15:37:09 +0100 Subject: [PATCH] Test throwing inside constructors --- .../async_notifier/async_notifier_test.dart | 19 +++++++++++++++++++ .../providers/notifier/notifier_test.dart | 19 +++++++++++++++++++ .../stream_notifier/async_notifier_test.dart | 19 +++++++++++++++++++ 3 files changed, 57 insertions(+) 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;