(app-desk) fix error warning jest test logout

We had a error warning in the jest test logout with fetchApi,
window.location.replace had to be mocked to avoid the error.
This commit is contained in:
Anthony LC
2024-02-26 16:18:56 +01:00
committed by Anthony LC
parent 65e78cde68
commit f17771fc9b

View File

@@ -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/',
);
});
});