side_effect_cubit_test 1.0.2 side_effect_cubit_test: ^1.0.2 copied to clipboard
This is a testing utility designed to simplify the process of testing Blocs that produce side effects. It builds upon the bloc_test package and introduces features that allow developers to expect side [...]
import "package:side_effect_cubit_test/side_effect_cubit_test.dart";
import "package:side_effect_cubit/side_effect_cubit.dart";
import "package:test/test.dart";
class CounterCubit extends SideEffectCubit<int, CounterSideEffect> {
CounterCubit() : super(0);
void plusOne() {
produceSideEffect(ShowInfoDialogEffect());
emit(state + 1);
}
}
abstract class CounterSideEffect {}
class ShowInfoDialogEffect extends CounterSideEffect {}
void main() {
final counterCubit = CounterCubit();
group("side_effect tests", () {
sideEffectBlocTest<CounterCubit, int, CounterSideEffect>(
"plusOne should yield ShowInfoDialogEffect",
build: () => counterCubit,
act: (cubit) => cubit.plusOne(),
expect: () => [1],
expectSideEffects: () => [isA<ShowInfoDialogEffect>()],
);
});
}