felangel / mocktail

A mock library for Dart inspired by mockito
https://pub.dev/packages/mocktail
MIT License
617 stars 81 forks source link

How to Mock a State? #223

Closed jassirr closed 7 months ago

jassirr commented 9 months ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

State MyState extends Equatable {

int value;

void getValue() { return state.value; }

} class MyBloc extends Bloc<MyEvent,MyState> { MyBloc() : super(MyState()) {

}

someFunction(event, emitter) { emit(state.copyWith(status: status.loading)); int value = state.getValue(); }

}

Expected behavior I want to mock this getValue function in my State class to in blocTest

Screenshots If applicable, add screenshots to help explain your problem.

Logs Run flutter analyze and attach any output of that command below. If there are any analysis errors, try resolving them before filing this issue.

Paste the output of running flutter doctor -v here.

Additional context Add any other context about the problem here.

felangel commented 8 months ago

You can use seed in blocTest to set the bloc’s state to whatever you like before adding events. Hope that helps!