-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for whenListenPresentation
- Loading branch information
Krzysztof Mamak
committed
Mar 13, 2024
1 parent
2a78f94
commit 3f7de24
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
packages/bloc_presentation_test/test/when_listen_presentation_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
}, | ||
); | ||
}); | ||
} |