Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make stream controller a broadcast one in whenListenPresentation #35

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.2

- Make `StreamController` a broadcast one in `whenListenPresentation`.

# 1.0.1

- Make `MockPresentationCubit` and `MockPresentationBloc` presentation streams broadcast ones.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ StreamController<T> whenListenPresentation<T>(
BlocPresentationMixin<dynamic, T> bloc, {
List<T>? initialEvents,
}) {
final presentationController = StreamController<T>();
final presentationController = StreamController<T>.broadcast();

initialEvents?.forEach(presentationController.add);

Expand Down
2 changes: 1 addition & 1 deletion packages/bloc_presentation_test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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<StreamSubscription<dynamic>> 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,
);
},
);
});
}
Loading