-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
45 lines (41 loc) · 1.1 KB
/
jest.setup.js
File metadata and controls
45 lines (41 loc) · 1.1 KB
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
42
43
44
45
// Import jest-dom additions for additional matchers
import '@testing-library/jest-dom';
// Add Request and Response polyfills for testing environment
const { Request, Response } = require('node-fetch');
global.Request = Request;
global.Response = Response;
// Mock the next/router module
jest.mock('next/router', () => ({
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
prefetch: jest.fn(),
back: jest.fn(),
pathname: '/',
query: {},
}),
}));
// Mock next-auth
jest.mock('next-auth/react', () => {
const originalModule = jest.requireActual('next-auth/react');
return {
__esModule: true,
...originalModule,
signIn: jest.fn(),
signOut: jest.fn(),
useSession: jest.fn(() => {
return { data: null, status: 'unauthenticated' };
}),
};
});
// Add custom matchers
expect.extend({
toHaveClass(received, ...expected) {
const pass = expected.every(className => received.classList.contains(className));
return {
message: () =>
`expected ${received} ${pass ? 'not ' : ''}to have class ${expected.join(' ')}`,
pass,
};
},
});