Skip to content

Commit

Permalink
Merge pull request #34 from leancodepl/bug/test-stream-broadcast
Browse files Browse the repository at this point in the history
Make MockPresentation{Cubit,Bloc} stream a broadcast one
  • Loading branch information
Albert221 authored Feb 7, 2024
2 parents 95a4ca3 + 3be013c commit ac557f4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/bloc_presentation_test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.0.1

- Make `MockPresentationCubit` and `MockPresentationBloc` presentation streams broadcast ones.

# 1.0.0

- Bump dependency on `bloc_presentation` to `^1.0.0`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class _MockPresentationBlocBase<S, P> extends Mock
when(close).thenAnswer((_) => _presentationController.close());
}

final _presentationController = StreamController<P>();
final _presentationController = StreamController<P>.broadcast();

/// Adds given [event] to bloc's presentation stream.
void emitMockPresentation(P event) {
Expand Down
8 changes: 4 additions & 4 deletions packages/bloc_presentation_test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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.0.1
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
Expand All @@ -19,4 +19,4 @@ dependencies:

dev_dependencies:
equatable: ^2.0.5
leancode_lint: '>=5.0.0'
leancode_lint: ">=5.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down

0 comments on commit ac557f4

Please sign in to comment.