Skip to content

Commit 806720c

Browse files
fixed test errors
1 parent 8c2c5a3 commit 806720c

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

frontend/lib/api/client.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { OfflineActionQueuedError } from '../offline';
55
describe('apiCall', () => {
66
const originalFetch = global.fetch;
77
const originalNavigator = global.navigator;
8+
89
const localStorageMock = (() => {
910
let store: Record<string, string> = {};
1011
return {
@@ -96,12 +97,17 @@ describe('apiCall', () => {
9697
});
9798

9899
it('does not retry aborted requests', async () => {
100+
// Use real timers to avoid timeout
101+
vi.useRealTimers();
102+
99103
const abortError = new DOMException('The operation was aborted.', 'AbortError');
100104
const fetchMock = vi.fn().mockRejectedValue(abortError);
101105

102106
global.fetch = fetchMock as typeof fetch;
103107

104-
await expect(apiCall('/health')).rejects.toMatchObject({
108+
await expect(
109+
apiCall('/health', {}, { maxRetries: 0 }) // prevent retry delays
110+
).rejects.toMatchObject({
105111
name: 'AbortError',
106112
});
107113
expect(fetchMock).toHaveBeenCalledTimes(1);
@@ -124,4 +130,4 @@ describe('apiCall', () => {
124130
expect(stored).toBeTruthy();
125131
expect(JSON.parse(stored as string)).toHaveLength(1);
126132
});
127-
});
133+
});

0 commit comments

Comments
 (0)