-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make stream controller a broadcast one in
whenListenPresentation
- Loading branch information
Showing
4 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
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, | ||
); | ||
}, | ||
); | ||
}); | ||
} |