From f17771fc9bc60349ed791b69ca55baac09cd6f42 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Mon, 26 Feb 2024 16:18:56 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85(app-desk)=20fix=20error=20warning=20j?= =?UTF-8?q?est=20test=20logout?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We had a error warning in the jest test logout with fetchApi, window.location.replace had to be mocked to avoid the error. --- .../apps/desk/src/api/__tests__/fetchApi.test.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/frontend/apps/desk/src/api/__tests__/fetchApi.test.tsx b/src/frontend/apps/desk/src/api/__tests__/fetchApi.test.tsx index 0976bf4..eeedd0c 100644 --- a/src/frontend/apps/desk/src/api/__tests__/fetchApi.test.tsx +++ b/src/frontend/apps/desk/src/api/__tests__/fetchApi.test.tsx @@ -34,6 +34,15 @@ describe('fetchAPI', () => { }); it('logout if 401 response', async () => { + const mockReplace = jest.fn(); + Object.defineProperty(window, 'location', { + configurable: true, + enumerable: true, + value: { + replace: mockReplace, + }, + }); + useAuthStore.setState({ userData: { email: 'test@test.com' } }); fetchMock.mock('http://some.api.url/api/v1.0/some/url', 401); @@ -41,5 +50,9 @@ describe('fetchAPI', () => { await fetchAPI('some/url'); expect(useAuthStore.getState().userData).toBeUndefined(); + + expect(mockReplace).toHaveBeenCalledWith( + 'http://some.api.url/api/v1.0/authenticate/', + ); }); });