Megha Rawat
Megha Rawat

Reputation: 195

How to test useParam() function with Jest

Getting this error while testing a component having a hook useParam()

Upvotes: 5

Views: 5578

Answers (1)

Megha Rawat
Megha Rawat

Reputation: 195

I fixed it using below code.
  jest.mock('react-router-dom', () => ({
    ...jest.requireActual('react-router-dom'),
    useParams: () => ({
      connectionId: '12',
    }),
  }));

Upvotes: 11

Related Questions