Skip to content

Unable to mock useAuth with jest #1290

Open
@raghavi92

Description

@raghavi92

I went through this already existing issue:
#372

But my mock for the useAuth function is simply not working. Can someone help please ?

I added the below code segment to my test file:

const auth = require('react-oidc-context');
jest.mock('react-oidc-context', () => {
  const orig = jest.requireActual('react-oidc-context');
  return {
    __esModule: true,
    default: jest.fn(),
    useAuth: jest.fn(),
    ...orig,
  };
});
  auth.useAuth.mockResolvedValue('test');
  render(<App />, {
    wrapper: ({ children }) => (
      <AuthProvider
        authority='authority'
        client_id='client'
        redirect_uri='redirect'
      >
        {children}
      </AuthProvider>
    ),
  });

  waitFor(() => {
    expect(
      screen.getByText('Tournaments managed by Lotus Chess Academy')
    ).toBeInTheDocument();
  });
});

I'm getting the error TypeError: auth.useAuth.mockResolvedValue is not a function.
I have a nextjs project with typescript enabled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions