bloc_presentation_test

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

bloc presentation test

bloc_presentation_test #


A package which makes testing BlocPresentationMixined Blocs/Cubits more straightforward.
To be used with bloc_presentation package.
Installation #
flutter pub add --dev bloc_presentation_test
copied to clipboard
Usage #
There are 2 ways of stubbing presentation stream:

using whenListenPresentation function
extending target BlocPresentationMixined Bloc/Cubit with MockPresentationBloc/MockPresentationCubit

1. Approach - whenListenPresentation #
First, create a mock class of your BlocPresentationMixined Bloc/Cubit.
For example, you can use bloc_test package to achieve that.
class MockCommentCubit extends MockCubit implements CommentCubit {}
copied to clipboard
Then, create an instance of MockCommentCubit and obtain StreamController by calling whenListenPresentation with
a newly created mocked cubit.
final mockCubit = MockCommentCubit();

final controller = whenListenPresentation(mockCubit);
copied to clipboard
It will stub MockCommentCubit's presentation stream, so you are able to subscribe to this stream.
Obtained controller can be used for adding events to presentation stream.
The returned StreamController is disposed in Cubit's/Bloc's close method.
If you override the stub for this method then you need to dispose the controller manually.
controller.add(const FailedToUpvote());
copied to clipboard
If you specify initialEvents argument, presentation stream will be stubbed with a stream of given events.
final controller = whenListenPresentation(
mockCubit,
const [FailedToUpvote(), SuccessfulUpvote()],
);
copied to clipboard
2. Approach - MockPresentationCubit/MockPresentationBloc #
First, create a mock class of your BlocPresentationMixined Bloc/Cubit using MockPresentationBloc/MockPresentationCubit.
class MockCommentCubit extends MockPresentationCubit<CommentState> implements CommentCubit {}
copied to clipboard
Then, create an instance of a MockCommentCubit and call emitMockPresentation.
final mockCubit = MockCommentCubit();

mockCubit.emitMockPresentation(const FailedToUpvote());
copied to clipboard
It will add FailedToUpvoteEvent to presentation stream.
After all, remember to call MockCommentCubit's close method.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files:

Customer Reviews

There are no reviews.