bloc_test library

A testing library which makes it easy to test blocs.

Get started at bloclibrary.dev 🚀

Classes

MockBloc<E, S>
Extend or mixin this class to mark the implementation as a MockBloc.
MockCubit<S>
Extend or mixin this class to mark the implementation as a MockCubit.

Functions

blocTest<B extends BlocBase<State>, State>(String description, {required B build(), FutureOr<void> setUp()?, State seed()?, dynamic act(B bloc)?, Duration? wait, int skip = 0, dynamic expect()?, dynamic verify(B bloc)?, dynamic errors()?, FutureOr<void> tearDown()?, dynamic tags}) → void
Creates a new bloc-specific test case with the given description. blocTest will handle asserting that the bloc emits the expected states (in order) after act is executed. blocTest also handles ensuring that no additional states are emitted by closing the bloc stream before evaluating the expectation.
testBloc<B extends BlocBase<State>, State>({required B build(), FutureOr<void> setUp()?, State seed()?, dynamic act(B bloc)?, Duration? wait, int skip = 0, dynamic expect()?, dynamic verify(B bloc)?, dynamic errors()?, FutureOr<void> tearDown()?}) → Future<void>
Internal blocTest runner which is only visible for testing. This should never be used directly -- please use blocTest instead.
whenListen<State>(BlocBase<State> bloc, Stream<State> stream, {State? initialState}) → void
Creates a stub response for the listen method on a bloc. Use whenListen if you want to return a canned Stream of states for a bloc instance.