Auth0 Home Blog Docs

E2e Testing React SPA with Cypress

I have added user login to a React application using the following guide: https://auth0.com/docs/quickstart/spa/react/01-login

This all works fine, but when I want to test the application in Cypress I am having some problems. I was initially following this guide: https://auth0.com/blog/end-to-end-testing-with-cypress-and-auth0 and this seems to implement the best practices from Cypress by using the password grant to log the user in before running the tests.

However, this guide isn’t using the auth0-spa-js library and implements its own container for storing the access token (https://github.com/danlourenco/auth0-cypress-demo/blob/base/src/Auth.js#L39-L48).

auth0-spa-js has its own logic for caching the access token.

Is it possible to use the auth0-spa-js library and use the password grant type for Cypress tests?

Thanks

3 Likes