Unit testing with Auth0

I have an app that was created with Create-React-App and from the quick starts I have an Auth0Provider component. That basically wraps the main component like:

ReactDOM.render(
    <Provider store={store}>
        <ConnectedRouter history={history}>
            <Auth0Provider
                domain={config.domain}
                clientId={config.client_id}
                redirectUri={window.location.origin}
            >
                <App />
            </Auth0Provider>
        </ConnectedRouter>
    </Provider>,
    document.getElementById('root'));

The problem comes with testing this code. My test looks like

  const { container } = render(
    <Provider store={store}>
      <MemoryRouter>
        <App />
      </MemoryRouter>
    </Provider>
  );

Notice that I have not rendered the component because I get a message that ‘window.cryto’ is required. How can I essentially ‘mock’ this component (which is how the App is wrapped) for unit testing?

Hey there!

Unfortunately I’m not a JS guy but maybe some of our docs for testing will guide you:

None of those are of any value,…,

  • The first one is all about testing Auth0 before it’s deployed
  • The second on is all about pushing manual tests at Auth0

What we need is a way to write unit tests or functional tests for Auth0 applications.
This (Testing React Applications with Jest) looks like a great article, but it’s four years old and of little value at this point.

1 Like

Unfortunately we don’t have more content on such topics but you can always advocate for that by creating a new topic in our Feedback category here: