diff --git a/jest.config.js b/jest.config.js index e72e449..bd0921d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -19,4 +19,5 @@ module.exports = { './test/mock-next-link.tsx', './test/setup-tests.ts', ], + resetMocks: true, }; diff --git a/test/pages/fixtures.test.tsx b/test/pages/fixtures.test.tsx index e26e0ff..5333e1f 100644 --- a/test/pages/fixtures.test.tsx +++ b/test/pages/fixtures.test.tsx @@ -6,17 +6,18 @@ import { mockFixturePreviews } from '../../src/domain/fixture/data/FixturePrevie import Fixtures from '../../src/pages/fixtures'; import { render, screen } from '../testUtils'; -const mockPush = jest.fn(); -const mockNextRouter: Partial = { push: mockPush }; -jest - .spyOn(nextRouter, 'useRouter') - .mockReturnValue(mockNextRouter as nextRouter.NextRouter); -jest.spyOn(fixtureApi, 'getFixtures').mockResolvedValue(mockFixturePreviews); - +const mockNextRouter: Partial = { push: jest.fn() }; const { id, homeTeamName } = mockFixturePreviews[0]; describe('Fixtures page', () => { beforeEach(() => { + jest + .spyOn(nextRouter, 'useRouter') + .mockReturnValue(mockNextRouter as nextRouter.NextRouter); + jest + .spyOn(fixtureApi, 'getFixtures') + .mockResolvedValue(mockFixturePreviews); + render(); }); @@ -37,7 +38,10 @@ describe('Fixtures page', () => { userEvent.click(fixtureComponent); - expect(mockPush).toBeCalledTimes(1); - expect(mockPush).toBeCalledWith(`fixtures/${id}`, `fixtures/${id}`); + expect(mockNextRouter.push).toBeCalledTimes(1); + expect(mockNextRouter.push).toBeCalledWith( + `fixtures/${id}`, + `fixtures/${id}` + ); }); }); diff --git a/test/pages/fixtures/[id].test.tsx b/test/pages/fixtures/[id].test.tsx index d73caf2..74f6311 100644 --- a/test/pages/fixtures/[id].test.tsx +++ b/test/pages/fixtures/[id].test.tsx @@ -25,16 +25,19 @@ const { id, homeTeamName, awayTeamName, events } = mockFixture; const mockNextRouter: Partial = { query: { id }, }; -jest - .spyOn(nextRouter, 'useRouter') - .mockReturnValue(mockNextRouter as nextRouter.NextRouter); - -const getFixtureSpy = jest - .spyOn(fixtureApi, 'getFixture') - .mockResolvedValue(mockFixture); describe('Fixture page', () => { + let getFixtureSpy; + beforeEach(() => { + jest + .spyOn(nextRouter, 'useRouter') + .mockReturnValue(mockNextRouter as nextRouter.NextRouter); + + getFixtureSpy = jest + .spyOn(fixtureApi, 'getFixture') + .mockResolvedValue(mockFixture); + render(); });