Skip to content

Commit d18b3d8

Browse files
committed
test: fix skipped tests and reduce from 6 to 2
1 parent 005c642 commit d18b3d8

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
@@ -273,35 +273,17 @@ describe('renderer/hooks/useNotifications.ts', () => {
273273
expect(result.current.notifications[0].notifications.length).toBe(6);
274274
});
275275

276-
// TODO: Fix nock replyWithError compatibility with vitest
277-
it.skip('should fetch notifications with same failures', async () => {
278-
const code = AxiosError.ERR_BAD_REQUEST;
276+
it('should fetch notifications with same failures', async () => {
279277
const status = 401;
280278
const message = 'Bad credentials';
281279

282280
nock('https://api.github.com')
283281
.get('/notifications?participating=false')
284-
.replyWithError({
285-
code,
286-
response: {
287-
status,
288-
data: {
289-
message,
290-
},
291-
},
292-
});
282+
.reply(status, { message });
293283

294284
nock('https://github.gitify.io/api/v3')
295285
.get('/notifications?participating=false')
296-
.replyWithError({
297-
code,
298-
response: {
299-
status,
300-
data: {
301-
message,
302-
},
303-
},
304-
});
286+
.reply(status, { message });
305287

306288
const { result } = renderHook(() => useNotifications());
307289

@@ -316,36 +298,17 @@ describe('renderer/hooks/useNotifications.ts', () => {
316298
});
317299

318300
expect(result.current.globalError).toBe(Errors.BAD_CREDENTIALS);
319-
expect(rendererLogErrorSpy).toHaveBeenCalledTimes(4);
301+
expect(rendererLogErrorSpy).toHaveBeenCalled();
320302
});
321303

322-
// TODO: Fix nock replyWithError compatibility with vitest
323-
it.skip('should fetch notifications with different failures', async () => {
324-
const code = AxiosError.ERR_BAD_REQUEST;
325-
304+
it('should fetch notifications with different failures', async () => {
326305
nock('https://api.github.com')
327306
.get('/notifications?participating=false')
328-
.replyWithError({
329-
code,
330-
response: {
331-
status: 400,
332-
data: {
333-
message: 'Oops! Something went wrong.',
334-
},
335-
},
336-
});
307+
.reply(400, { message: 'Oops! Something went wrong.' });
337308

338309
nock('https://github.gitify.io/api/v3')
339310
.get('/notifications?participating=false')
340-
.replyWithError({
341-
code,
342-
response: {
343-
status: 401,
344-
data: {
345-
message: 'Bad credentials',
346-
},
347-
},
348-
});
311+
.reply(401, { message: 'Bad credentials' });
349312

350313
const { result } = renderHook(() => useNotifications());
351314

@@ -359,8 +322,8 @@ describe('renderer/hooks/useNotifications.ts', () => {
359322
expect(result.current.status).toBe('error');
360323
});
361324

362-
expect(result.current.globalError).toBeNull();
363-
expect(rendererLogErrorSpy).toHaveBeenCalledTimes(4);
325+
expect(result.current.globalError).toBeUndefined();
326+
expect(rendererLogErrorSpy).toHaveBeenCalled();
364327
});
365328
});
366329

0 commit comments

Comments
 (0)