form_bloc
form_bloc copied to clipboard
how to test form_bloc with BlocMock and MockRepository?
Could you give us an example how to test the form and the bloc separately in the form_bloc organization?
Regards, Hans
This is a serious question. If anyone got at least one great example, I'm more than glad to look at it
Hello everyone, Any news ?
I am new to flutter Testing and I only manage to test a simple thing but I don't know how to test the value sent from a TextField or to access the state.
This my test bloc :
class MockPasswordForgotFormBloc extends MockBloc<FormBlocEvent, FormBlocState<String, String>>
implements PasswordForgotFormBloc {}
void main() {
group("Unit test PasswordForgotFormBloc", () {
blocTest<PasswordForgotFormBloc,FormBlocState<String, String>>(
"initial state",
build: () => PasswordForgotFormBloc(),
expect: () => [
UpdateFormBlocState(FormBlocLoaded()) // this fails because of toJson & fieldBlocs
]
);
blocTest<PasswordForgotFormBloc,FormBlocState<String, String>>(
"when user submit nothing",
build: () => PasswordForgotFormBloc(),
act: (bloc) => bloc.submit(),
verify: (bloc) {
return bloc.state.isValid() == false;
}
);
});
}
This is my PasswordForgotFormBloc :
class PasswordForgotFormBloc extends FormBloc<String, String> {
final email = TextFieldBloc(
validators: [
FieldBlocValidators.required,
FieldBlocValidators.email,
],
);
PasswordForgotFormBloc() {
addFieldBlocs(fieldBlocs: [email]);
}
@override
void onSubmitting() async {
// TODO : add connexion to firebase or any other database to login
try {
await Future<void>.delayed(const Duration(milliseconds: 500));
emitSuccess();
} catch (e) {
emitFailure();
}
}
}
So does anyone have an answer after 2 years ^^ ?
@nicolasvanheusden https://pub.dev/packages/flutter_floc
@IzioDev Ooh Ok flutter_form_bloc is not maintained anymore. I see thx !
Hello there, any updates on how to add test to forms?