Skip to content

Commit 3551986

Browse files
authored
Merge pull request #22 from James-Cross/staging
refactor: improve comments and error handling in Jest setup
2 parents 4d253a3 + d5c871a commit 3551986

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

jest.setup.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// jest.setup.ts
22
import '@testing-library/jest-dom';
33

4-
// Provide a global fetch mock for components using fetch
4+
// Mock global fetch
55
global.fetch = jest.fn(() =>
66
Promise.resolve({
77
json: () => Promise.resolve([
@@ -25,10 +25,13 @@ global.fetch = jest.fn(() =>
2525
})
2626
) as jest.Mock;
2727

28-
// Suppress React act(...) warnings globally (Jest syntax)
28+
// Suppress React act(...) warnings globally
29+
const originalError = console.error;
30+
2931
beforeAll(() => {
30-
jest.spyOn(console, 'error').mockImplementation((msg) => {
32+
jest.spyOn(console, 'error').mockImplementation((...args) => {
33+
const [msg] = args;
3134
if (typeof msg === 'string' && msg.includes('not wrapped in act')) return;
32-
console.error(msg);
35+
originalError(...args);
3336
});
3437
});

0 commit comments

Comments
 (0)