When it comes to mocking a standard npm project, the process is simple. Just create a __mocks__
folder next to the node_modules folder, then name the file after the package and insert the mock contents.
For example: /__mocks__/axios.ts
However, I encountered an issue with a npm package import that looks like this: @auth0/auth0-react
How can I mock the contents of this file? I attempted to create a file named @auth0/auth0-react.tsx
, but jest doesn't recognize the mocked file. When I import
import { Auth0Provider } from '@auth0/auth0-react';
and console.log(Auth0Provider)
, all I see are the standard Jest.fn()
attributes.
Below are the contents of the mocked file:
/* eslint-disable import/prefer-default-export */
export const Auth0Provider = (component: JSX.Element): JSX.Element => component;
Since I did not utilize jest.fn()
on this method, I am hoping that console.log(Auth0Provider)
will display that it includes a function.
In my test code, I have jest.mock('@auth0/auth0-react')
before running my test. Any suggestions?