diff --git a/packages/bloc_presentation_test/CHANGELOG.md b/packages/bloc_presentation_test/CHANGELOG.md index 8f4e849..bbf5e52 100644 --- a/packages/bloc_presentation_test/CHANGELOG.md +++ b/packages/bloc_presentation_test/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.0.2 + +- Make `StreamController` a broadcast one in `whenListenPresentation`. + # 1.0.1 - Make `MockPresentationCubit` and `MockPresentationBloc` presentation streams broadcast ones. diff --git a/packages/bloc_presentation_test/lib/src/when_listen_presentation.dart b/packages/bloc_presentation_test/lib/src/when_listen_presentation.dart index c9faa4e..66a85e2 100644 --- a/packages/bloc_presentation_test/lib/src/when_listen_presentation.dart +++ b/packages/bloc_presentation_test/lib/src/when_listen_presentation.dart @@ -13,7 +13,7 @@ StreamController whenListenPresentation( BlocPresentationMixin bloc, { List? initialEvents, }) { - final presentationController = StreamController(); + final presentationController = StreamController.broadcast(); initialEvents?.forEach(presentationController.add); diff --git a/packages/bloc_presentation_test/pubspec.yaml b/packages/bloc_presentation_test/pubspec.yaml index 6c8689a..2f7c26c 100644 --- a/packages/bloc_presentation_test/pubspec.yaml +++ b/packages/bloc_presentation_test/pubspec.yaml @@ -1,6 +1,6 @@ name: bloc_presentation_test description: A testing library for Blocs/Cubits which mixin BlocPresentationMixin. To be used with bloc_presentation package. -version: 1.0.1 +version: 1.0.2 homepage: https://github.com/leancodepl/bloc_presentation/tree/master/packages/bloc_presentation_test environment: diff --git a/packages/bloc_presentation_test/test/when_listen_presentation_test.dart b/packages/bloc_presentation_test/test/when_listen_presentation_test.dart new file mode 100644 index 0000000..345b0d2 --- /dev/null +++ b/packages/bloc_presentation_test/test/when_listen_presentation_test.dart @@ -0,0 +1,57 @@ +import 'dart:async'; + +import 'package:bloc_presentation_test/bloc_presentation_test.dart'; +import 'package:mocktail/mocktail.dart'; +import 'package:test/expect.dart'; +import 'package:test/scaffolding.dart'; + +import 'cubits/counter_cubit.dart'; + +class _MockCounterCubit extends Mock implements CounterCubit {} + +void main() { + late _MockCounterCubit cubit; + late List> subscriptions; + + setUp(() { + cubit = _MockCounterCubit(); + + subscriptions = []; + }); + + tearDown(() async { + await cubit.close(); + await subscriptions.map((sub) => sub.cancel()).wait; + }); + + group('whenListenPresentation', () { + test( + 'returns controller whose stream can be listened to more than once', + () { + final controller = whenListenPresentation(cubit); + + subscriptions.add(controller.stream.listen((_) {})); + + expect( + () => subscriptions.add(controller.stream.listen((_) {})), + returnsNormally, + ); + }, + ); + + test( + 'stubs cubit presentation with a stream that can be listened to more ' + 'than once', + () { + whenListenPresentation(cubit); + + subscriptions.add(cubit.presentation.listen((_) {})); + + expect( + () => subscriptions.add(cubit.presentation.listen((_) {})), + returnsNormally, + ); + }, + ); + }); +}