chore(react-router-v6): Fixing navigation in the lighthouse plugin

This commit is contained in:
blam
2020-06-11 20:20:58 +02:00
parent da493b1fc9
commit 47766635b6
3 changed files with 9 additions and 16 deletions
@@ -16,13 +16,10 @@
jest.mock('react-router-dom', () => {
const actual = jest.requireActual('react-router-dom');
const mocks = {
replace: jest.fn(),
push: jest.fn(),
};
const mockNavigation = jest.fn();
return {
...actual,
useNavigate: jest.fn(() => mocks),
useNavigate: jest.fn(() => mockNavigation),
};
});
@@ -145,9 +142,8 @@ describe('AuditList', () => {
);
const element = await rendered.findByLabelText(/Go to page 1/);
fireEvent.click(element);
expect(useNavigate().replace).toHaveBeenCalledWith(
`/lighthouse?page=1`,
);
expect(useNavigate()).toHaveBeenCalledWith(`/lighthouse?page=1`);
});
});
});
@@ -21,6 +21,7 @@ import {
Grid,
List,
ListItem,
Button,
ListItemIcon,
ListItemText,
} from '@material-ui/core';
@@ -32,7 +33,6 @@ import {
Header,
Page,
Content,
Button,
ContentHeader,
HeaderLabel,
Progress,
@@ -16,13 +16,10 @@
jest.mock('react-router-dom', () => {
const actual = jest.requireActual('react-router-dom');
const mocks = {
replace: jest.fn(),
push: jest.fn(),
};
const mockNavigate = jest.fn();
return {
...actual,
useNavigate: jest.fn(() => mocks),
useNavigate: jest.fn(() => mockNavigate),
};
});
@@ -115,7 +112,7 @@ describe('CreateAudit', () => {
describe('when the audit is successfully created', () => {
it('triggers a location change to the table', async () => {
useNavigate().push.mockClear();
useNavigate.mockClear();
mockFetch.mockResponseOnce(JSON.stringify(createAuditResponse));
const rendered = render(
@@ -140,7 +137,7 @@ describe('CreateAudit', () => {
await wait(() => expect(rendered.getByLabelText(/URL/)).toBeEnabled());
expect(useNavigate().push).toHaveBeenCalledWith('/lighthouse');
expect(useNavigate()).toHaveBeenCalledWith('/lighthouse');
});
});