-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
41 lines (35 loc) · 950 Bytes
/
jest.setup.js
File metadata and controls
41 lines (35 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import '@testing-library/jest-dom';
// Polyfill for TextEncoder and TextDecoder
import { TextEncoder, TextDecoder } from 'util';
global.TextEncoder = TextEncoder;
global.TextDecoder = TextDecoder;
// Mock localForage
jest.mock('localforage', () => ({
getItem: jest.fn(),
setItem: jest.fn(),
removeItem: jest.fn(),
}));
// Mock react-router-dom
jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useNavigate: () => jest.fn(),
}));
// Setup global mocks if needed
global.fetch = jest.fn(() =>
Promise.resolve({
json: () => Promise.resolve({}),
})
);
// Silence React 18 console warnings in tests
const originalError = console.error;
beforeAll(() => {
console.error = (...args) => {
if (/Warning: ReactDOM.render is no longer supported in React 18./.test(args[0])) {
return;
}
originalError.call(console, ...args);
};
});
afterAll(() => {
console.error = originalError;
});