0

When I add this line to the test setup, the mocking of useParams stops to work. I cannot find why it happens.

testsetup.ts

import '@testing-library/jest-dom'

const queryClient = new QueryClient({
    defaultOptions: {
        queries: {
            retry: 3
        }
    }
})

// Clean up the react queries cache for each test.
afterEach(() => queryClient.clear())

component.test.tsx


jest.mock('react-router-dom', () => ({
    ...(jest.requireActual('react-router-dom') as any),
    useParams: () => ({
        tenantAlias: 'DE'
    })
}))

test('Showing a navigation', async () => {
   ... some tests
})

Tested component is using useParams() to get params['tenantAlias'], but with queryClient.clear() it stops to returned mocked data, otherwise it works correct.

Why??? :)

podeig
  • 2,597
  • 8
  • 36
  • 60

0 Answers0