Skip to content

Commit

Permalink
Add tests for whenListenPresentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Mamak committed Mar 13, 2024
1 parent 2a78f94 commit 3f7de24
Showing 1 changed file with 57 additions and 0 deletions.
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,
);
},
);
});
}

0 comments on commit 3f7de24

Please sign in to comment.