Search code examples
firebasefirebase-authenticatione2e-testingcypressangular-e2e

Preventing Firebase Auth from persisting across Cypress e2e test runs


I'm using Cypress for e2e tests on my Firebase web app, and I want test runs to always start fresh from an non-authenticated state.

How do I prevent Firebase Auth sessions from persisting across e2e test runs?

Currently, I have a logout() function call at the end of the tests. But if a test fails before that point, logout() often doesn't get called, and I have to manually log out before the next test run.


Solution

  • Hi as mentioned you should clear firebase auth token in your beforeEach() method.

    However depending on the version of firebase the auth token might be stored in different storage. Localstorage and indexdDB should be cleared.

    indexedDB.deleteDatabase('firebaseLocalStorageDb');