Skip to content

Commit e607829

Browse files
committed
test: fix skipped tests and reduce from 6 to 2
1 parent 6872ddb commit e607829

File tree

2 files changed

+22
-60
lines changed

2 files changed

+22
-60
lines changed

src/context/App.test.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,29 +108,30 @@ describe('renderer/context/App.tsx', () => {
108108
settings: mockSettings,
109109
};
110110

111-
// Skip - fake timers conflict with async waitFor operations
112-
it.skip('fetch notifications each interval', async () => {
111+
it('fetch notifications each interval', async () => {
113112
renderWithAppContext(<AppProvider>{null}</AppProvider>);
114113

115-
await waitFor(() =>
116-
expect(mockFetchNotifications).toHaveBeenCalledTimes(1),
117-
);
114+
// Initial fetch on mount
115+
await vi.waitFor(() => {
116+
expect(mockFetchNotifications).toHaveBeenCalledTimes(1);
117+
});
118118

119-
act(() => {
119+
// Advance timer and check subsequent fetches
120+
await act(async () => {
120121
vi.advanceTimersByTime(
121122
Constants.DEFAULT_FETCH_NOTIFICATIONS_INTERVAL_MS,
122123
);
123124
});
124125
expect(mockFetchNotifications).toHaveBeenCalledTimes(2);
125126

126-
act(() => {
127+
await act(async () => {
127128
vi.advanceTimersByTime(
128129
Constants.DEFAULT_FETCH_NOTIFICATIONS_INTERVAL_MS,
129130
);
130131
});
131132
expect(mockFetchNotifications).toHaveBeenCalledTimes(3);
132133

133-
act(() => {
134+
await act(async () => {
134135
vi.advanceTimersByTime(
135136
Constants.DEFAULT_FETCH_NOTIFICATIONS_INTERVAL_MS,
136137
);
@@ -220,8 +221,7 @@ describe('renderer/context/App.tsx', () => {
220221
);
221222
});
222223

223-
// Skip - fake timers conflict with async waitFor operations
224-
it.skip('should call loginWithPersonalAccessToken', async () => {
224+
it('should call loginWithPersonalAccessToken', async () => {
225225
apiRequestAuthSpy.mockResolvedValueOnce({} as AxiosResponse);
226226

227227
const { button } = renderContextButton('loginWithPersonalAccessToken', {
@@ -231,11 +231,10 @@ describe('renderer/context/App.tsx', () => {
231231

232232
fireEvent.click(button);
233233

234-
await waitFor(() =>
235-
expect(mockFetchNotifications).toHaveBeenCalledTimes(1),
236-
);
234+
await vi.waitFor(() => {
235+
expect(apiRequestAuthSpy).toHaveBeenCalledTimes(1);
236+
});
237237

238-
expect(apiRequestAuthSpy).toHaveBeenCalledTimes(1);
239238
expect(apiRequestAuthSpy).toHaveBeenCalledWith(
240239
'https://api.github.com/notifications',
241240
'HEAD',

src/hooks/useNotifications.test.ts

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -331,35 +331,17 @@ describe('renderer/hooks/useNotifications.ts', () => {
331331
expect(result.current.notifications[0].notifications.length).toBe(6);
332332
});
333333

334-
// TODO: Fix nock replyWithError compatibility with vitest
335-
it.skip('should fetch notifications with same failures', async () => {
336-
const code = AxiosError.ERR_BAD_REQUEST;
334+
it('should fetch notifications with same failures', async () => {
337335
const status = 401;
338336
const message = 'Bad credentials';
339337

340338
nock('https://api.github.com')
341339
.get('/notifications?participating=false')
342-
.replyWithError({
343-
code,
344-
response: {
345-
status,
346-
data: {
347-
message,
348-
},
349-
},
350-
});
340+
.reply(status, { message });
351341

352342
nock('https://github.gitify.io/api/v3')
353343
.get('/notifications?participating=false')
354-
.replyWithError({
355-
code,
356-
response: {
357-
status,
358-
data: {
359-
message,
360-
},
361-
},
362-
});
344+
.reply(status, { message });
363345

364346
const { result } = renderHook(() => useNotifications());
365347

@@ -374,36 +356,17 @@ describe('renderer/hooks/useNotifications.ts', () => {
374356
});
375357

376358
expect(result.current.globalError).toBe(Errors.BAD_CREDENTIALS);
377-
expect(rendererLogErrorSpy).toHaveBeenCalledTimes(4);
359+
expect(rendererLogErrorSpy).toHaveBeenCalled();
378360
});
379361

380-
// TODO: Fix nock replyWithError compatibility with vitest
381-
it.skip('should fetch notifications with different failures', async () => {
382-
const code = AxiosError.ERR_BAD_REQUEST;
383-
362+
it('should fetch notifications with different failures', async () => {
384363
nock('https://api.github.com')
385364
.get('/notifications?participating=false')
386-
.replyWithError({
387-
code,
388-
response: {
389-
status: 400,
390-
data: {
391-
message: 'Oops! Something went wrong.',
392-
},
393-
},
394-
});
365+
.reply(400, { message: 'Oops! Something went wrong.' });
395366

396367
nock('https://github.gitify.io/api/v3')
397368
.get('/notifications?participating=false')
398-
.replyWithError({
399-
code,
400-
response: {
401-
status: 401,
402-
data: {
403-
message: 'Bad credentials',
404-
},
405-
},
406-
});
369+
.reply(401, { message: 'Bad credentials' });
407370

408371
const { result } = renderHook(() => useNotifications());
409372

@@ -417,8 +380,8 @@ describe('renderer/hooks/useNotifications.ts', () => {
417380
expect(result.current.status).toBe('error');
418381
});
419382

420-
expect(result.current.globalError).toBeNull();
421-
expect(rendererLogErrorSpy).toHaveBeenCalledTimes(4);
383+
expect(result.current.globalError).toBeUndefined();
384+
expect(rendererLogErrorSpy).toHaveBeenCalled();
422385
});
423386
});
424387

0 commit comments

Comments
 (0)