Skip to content

Commit

Permalink
Fix Jest mock not working
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Smock <[email protected]>
  • Loading branch information
tsmock committed May 24, 2023
1 parent cfd806f commit dbec7f5
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions frontend/src/views/tests/fallback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import { FallbackComponent } from '../fallback';
import { SERVICE_DESK } from '../../config';
import messages from '../messages';

/*
* This was in "should trigger navigate on return button click". There are
* references to some things being hoisted to different locations in Jest
* documentation. For whatever reason, we have to mock it here, instead of later
* in the test where we actually need to mock it.
*/
const mockedUsedNavigate = jest.fn();
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => mockedUsedNavigate,
}));

describe('Fallback component', () => {
it('should render component details', () => {
renderWithRouter(
Expand Down Expand Up @@ -49,13 +61,6 @@ describe('Fallback component', () => {
});

it('should trigger navigate on return button click', async () => {
const mockedUsedNavigate = jest.fn();

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => mockedUsedNavigate,
}));

const { user } = renderWithRouter(
<IntlProviders>
<FallbackComponent />
Expand Down

0 comments on commit dbec7f5

Please sign in to comment.