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?



Having exactly same problem :frowning:. I able to retrieve the access token, but that is useless to me, since there is no way of providing this token to auth0-spa-js

I haven’t found an official solution and I would love one if possible. So far I’ve resorted to logging in manually and maintaining the local storage between the tests.

1 Like

Thanks for sharing it with the rest of community @vermvfx!

I’m also finding this to be an issue. I’m not sure what token/code or state to redirect too in order to continue the login process.

@konrad.sopala can you weigh in with an actual solution please?

1 Like

I did manage to resolve the problem in the end - https://stackoverflow.com/questions/59664721/how-to-test-single-page-application-with-cypress-and-auth0/59716793#59716793

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.