How to unit test @auth0/auth0-react

Here is an example. The simplest approach is to stub the withAuthenticationRequired method:

import {render} from '@testing-library/react';
import Profile from './Profile';

jest.mock("@auth0/auth0-react", () => ({
    withAuthenticationRequired: jest.fn().mockImplementation((component, ignore) => component)
}))

test('renders profile view', () => {
    const rendered = render(<Profile/>);
    const sectionHeading = rendered.container.querySelector("#profile-section-heading")
    expect(sectionHeading).toBeInTheDocument()
});

afterEach(() => jest.clearAllMocks())
1 Like