Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: How to test nested event's #4315

Open
iamtechieboy opened this issue Jan 5, 2025 · 0 comments
Open

docs: How to test nested event's #4315

iamtechieboy opened this issue Jan 5, 2025 · 0 comments
Labels
documentation Documentation requested

Comments

@iamtechieboy
Copy link

Thanks in advance for maintaining the package;

I was testing an event, inside that event other event was triggered; I used many way's to test it, but Could you guys give me guideline to use it correctly.

Thanks in advance;

The first event:
...
if (result.right.success) {
emit(
state.copyWith(
phone: event.phoneNumber,
isNewUser: false,
loginStatus: FormzSubmissionStatus.success,
email: result.right.email,
loginResponseEntity: result.right,
isInternationalPhone: state.selectedCountry.countryCode.toLowerCase() != "uz"),
);
add(GetVerificationCode()); // <= this is triggered;
}
...

test for the event :

blocTest<AuthBloc, AuthState>(
"should check phone number and continue as a registered user with local phone number",
build: () => authBloc,
setUp: () {
when(() => checkPhoneUseCaseMock.call(tPhoneNumber)).thenAnswer((_) async => Right(tCheckResponseEntity));
},
act: (bloc) {
bloc.add(CheckPhone(phoneNumber: tPhoneNumber));
},
expect: () => [
isA().having((state) => state.loginStatus, "progress state", FormzSubmissionStatus.inProgress),
isA()
.having((state) => state.loginStatus, "loginStatus", FormzSubmissionStatus.success)
.having((state) => state.isNewUser, "isNewUser", false)
.having((state) => state.phone, "phone", tPhoneNumber)
.having((state) => state.loginResponseEntity, "loginResponseEntity", tCheckResponseEntity)
.having((state) => state.isInternationalPhone, "isInternationalPhone", false)
.having((state) => state.email, "email", ""),
isA()
.having((state) => state.loginStatus, "loginStatus", FormzSubmissionStatus.initial)
.having((state) => state.message, "error message", ""),
],
verify: (bloc) {
// check phone number is called once
verify(() => checkPhoneUseCaseMock.call(tPhoneNumber)).called(1);

      final mockBloc = bloc as AuthBlocMock;
      expect(mockBloc.capturedEvents, contains(isA<GetVerificationCode>()));
    },
  );          
@iamtechieboy iamtechieboy added the documentation Documentation requested label Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Documentation requested
Projects
None yet
Development

No branches or pull requests

1 participant