-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.setup.ts
34 lines (32 loc) · 1.17 KB
/
jest.setup.ts
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
import { TextEncoder as NodeTextEncoder, TextDecoder as NodeTextDecoder } from "util";
import "@testing-library/jest-dom";
global.TextEncoder = NodeTextEncoder as unknown as typeof TextEncoder;
global.TextDecoder = NodeTextDecoder as unknown as typeof TextDecoder;
jest.mock('next/font/google', () => ({
Open_Sans: jest.fn(() => ({ className: 'mocked-class-name' }))
}));
jest.mock('query-string', () => ({
parse: jest.fn(),
stringify: jest.fn(),
stringifyUrl: jest.fn(({ url, query }) => {
const queryString = Object.entries(query).map(([key, value]) => `${key}=${value}`).join("&");
return `${url}?${queryString}`;
})
}));
jest.mock("date-fns", () => ({
...jest.requireActual("date-fns"),
format: jest.fn((date) => {
if (!(date instanceof Date) || isNaN(date.getTime())) {
return 'Invalid Date';
}
const options: Intl.DateTimeFormatOptions = {
day: "numeric",
month: "short",
year: "numeric",
hour: "2-digit",
minute: "2-digit",
hour12: false
};
return new Intl.DateTimeFormat("en-GB", options).format(date as Date);
})
}));