Skip to content

Commit dbcbfd9

Browse files
committed
Enhance API client tests with improved error handling and timeout settings
- Updated test cases in `apiClient.test.js` and `criticalFlows.test.js` to include timeout settings for better reliability during asynchronous operations. - Modified error handling assertions to provide more descriptive messages for fetch errors, ensuring clarity in test outcomes.
1 parent 8e8d750 commit dbcbfd9

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

tests/api/apiClient.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('APIClient', () => {
2424
expect(result[0]).toHaveProperty('username');
2525
});
2626

27-
it('should handle fetch errors', async () => {
27+
it('should handle fetch errors', { timeout: 10000 }, async () => {
2828
global.fetch = vi.fn(() =>
2929
Promise.reject(new Error('Network error'))
3030
);
@@ -98,7 +98,8 @@ describe('APIClient', () => {
9898
})
9999
);
100100

101-
await expect(apiClient.getUserIndex()).rejects.toThrow('HTTP error');
101+
// The API client transforms 404 errors to a more descriptive message
102+
await expect(apiClient.getUserIndex()).rejects.toThrow('Resource not found');
102103
});
103104
});
104105
});

tests/integration/criticalFlows.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('Critical User Flows', () => {
7575
expect(filtered.length).toBeGreaterThan(0);
7676
});
7777

78-
it('should handle search errors gracefully', async () => {
78+
it('should handle search errors gracefully', { timeout: 10000 }, async () => {
7979
// Clear cache first
8080
apiClient.clearCache();
8181

@@ -253,7 +253,7 @@ describe('Critical User Flows', () => {
253253
});
254254

255255
describe('Flow 9: Error Handling', () => {
256-
it('should handle network errors', async () => {
256+
it('should handle network errors', { timeout: 10000 }, async () => {
257257
global.fetch.mockRejectedValue(new Error('Network error'));
258258

259259
await expect(apiClient.getMetadata()).rejects.toThrow();

0 commit comments

Comments
 (0)