From b303f974fdd0b3e4a76f0299efa32ec4a85ae9e0 Mon Sep 17 00:00:00 2001 From: Albert Wolszon Date: Wed, 7 Feb 2024 09:52:13 +0100 Subject: [PATCH] Make MockPresentation{Cubit,Bloc} stream a broadcast one --- packages/bloc_presentation_test/CHANGELOG.md | 4 ++++ .../lib/src/mock_presentation_bloc.dart | 2 +- packages/bloc_presentation_test/pubspec.yaml | 8 ++++---- .../test/bloc_presentation_test_test.dart | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/packages/bloc_presentation_test/CHANGELOG.md b/packages/bloc_presentation_test/CHANGELOG.md index f4390cb..51c5167 100644 --- a/packages/bloc_presentation_test/CHANGELOG.md +++ b/packages/bloc_presentation_test/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.1.0 + +- Make `MockPresentationCubit` and `MockPresentationBloc` presentation streams broadcast ones. + # 1.0.0 - Bump dependency on `bloc_presentation` to `^1.0.0` diff --git a/packages/bloc_presentation_test/lib/src/mock_presentation_bloc.dart b/packages/bloc_presentation_test/lib/src/mock_presentation_bloc.dart index e5f1b70..6369ea9 100644 --- a/packages/bloc_presentation_test/lib/src/mock_presentation_bloc.dart +++ b/packages/bloc_presentation_test/lib/src/mock_presentation_bloc.dart @@ -24,7 +24,7 @@ class _MockPresentationBlocBase extends Mock when(close).thenAnswer((_) => _presentationController.close()); } - final _presentationController = StreamController

(); + final _presentationController = StreamController

.broadcast(); /// Adds given [event] to bloc's presentation stream. void emitMockPresentation(P event) { diff --git a/packages/bloc_presentation_test/pubspec.yaml b/packages/bloc_presentation_test/pubspec.yaml index f0fcb94..d7504de 100644 --- a/packages/bloc_presentation_test/pubspec.yaml +++ b/packages/bloc_presentation_test/pubspec.yaml @@ -1,11 +1,11 @@ name: bloc_presentation_test description: A testing library for Blocs/Cubits which mixin BlocPresentationMixin. To be used with bloc_presentation package. -version: 1.0.0 +version: 1.1.0 homepage: https://github.com/leancodepl/bloc_presentation/tree/master/packages/bloc_presentation_test environment: - sdk: '>=3.0.0 <4.0.0' - flutter: '>=3.10.0' + sdk: ">=3.0.0 <4.0.0" + flutter: ">=3.10.0" dependencies: bloc: ^8.0.0 @@ -19,4 +19,4 @@ dependencies: dev_dependencies: equatable: ^2.0.5 - leancode_lint: '>=5.0.0' + leancode_lint: ">=5.0.0" diff --git a/packages/bloc_presentation_test/test/bloc_presentation_test_test.dart b/packages/bloc_presentation_test/test/bloc_presentation_test_test.dart index b5343c2..a14cb85 100644 --- a/packages/bloc_presentation_test/test/bloc_presentation_test_test.dart +++ b/packages/bloc_presentation_test/test/bloc_presentation_test_test.dart @@ -241,6 +241,20 @@ void main() { expect((actualError as TestFailure).message, expectedError); }, ); + + test('allows to listen to presentation stream three times', () { + final cubit = CounterCubit(); + + final subs = [ + cubit.presentation.listen((_) {}), + cubit.presentation.listen((_) {}), + cubit.presentation.listen((_) {}), + ]; + + for (final subscription in subs) { + subscription.cancel(); + } + }); }); group('AsyncCounterCubit', () {