Skip to content

Commit

Permalink
Fix some more unit tests using timers #1379
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Mar 14, 2024
1 parent 4b48f5e commit 07b9472
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 0 additions & 2 deletions __mocks__/axios.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// TODO: move __mocks__ folder back to root once facebook/create-react-app#7539 is fixed

const requests = {
get: vi.fn((path) => {
if (path === '/settings.json') {
Expand Down
7 changes: 4 additions & 3 deletions src/routing/routing.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ describe('Routing component', () => {

afterEach(() => {
vi.clearAllMocks();
vi.useRealTimers();
});

it('renders component with no plugin routes', () => {
Expand Down Expand Up @@ -393,7 +392,7 @@ describe('Routing component', () => {
});

it("single-spa reloads a plugin when it hasn't loaded for some reason", () => {
vi.useFakeTimers();
vi.useFakeTimers({ shouldAdvanceTime: true });
state.scigateway.authorisation.provider = new TestAuthProvider('logged in');
state.scigateway.siteLoading = false;
state.scigateway.plugins = [
Expand Down Expand Up @@ -421,9 +420,11 @@ describe('Routing component', () => {
'test_plugin_name'
);

expect(clearIntervalSpy).toHaveBeenCalledWith(expect.any(Number));
// Could not use toHaveBeenCalledWith(expect.any(Number)) as it is a mocked object in this test
expect(clearIntervalSpy).toHaveBeenCalled();

// restore clearInterval to avoid errors with it not being a function on unmount
clearIntervalSpy.mockRestore();
vi.useRealTimers();
});
});
2 changes: 1 addition & 1 deletion src/tour/tour.component.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('Tour component', () => {
content: 'Plugin link test',
},
];
vi.useFakeTimers();
vi.useFakeTimers({ shouldAdvanceTime: true });
const user = userEvent.setup({
advanceTimers: vi.advanceTimersByTime,
});
Expand Down

0 comments on commit 07b9472

Please sign in to comment.