samedi 30 janvier 2021

Tests don't pass using react-testing-library when adding firebase persistance, but when testing manually, everything works

I am testing my SingIn component in my React app. All tests passed until I added firebase.auth().setPersistance() to my submit handler. I use jest with react-testing-library for tests.

part of test that fails:

typeLoginCredentials(email, 'badpassword');
act(() => {
  userEvent.click(screen.getByText(/Login/));
});
expect(await screen.findByText(/Wrong password/)).toBeInTheDocument();

and part of my submit handler:

...
try {
  let persistence = rememberAuth ? firebase.auth.Auth.Persistence.LOCAL : 
                                   firebase.auth.Auth.Persistence.SESSION;
  await fireApp
    .auth()
    .setPersistence(persistence);
  await fireApp
     .auth()
     .signInWithEmailAndPassword(email, password);
...

When i test this manually in my browser, everything works fine. But tests pass only when I remove persistence part:

await fireApp.auth().setPersistence(persistence);

I even tried to change findBy timeout, but it didn't help.

Aucun commentaire:

Enregistrer un commentaire