-
Notifications
You must be signed in to change notification settings - Fork 11
/
jest.setup.js
42 lines (38 loc) · 1.04 KB
/
jest.setup.js
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
import { defaultLocale as mockDefaultLocale } from './intl';
// Mock Next.js router so that useRouter hook works.
jest.mock('next/router', () => {
const router = {
pathname: '/',
query: {},
asPath: '/',
locale: mockDefaultLocale,
events: {
on: jest.fn(),
off: jest.fn(),
emit: jest.fn(),
},
push: jest.fn(async () => {}),
replace: jest.fn(async () => {}),
reload: jest.fn(),
back: jest.fn(),
prefetch: jest.fn(async () => {}),
beforePopState: jest.fn(),
isFallback: false,
};
return {
__esModule: true,
default: router,
useRouter: () => router,
};
});
// Mock Next.js internal router so that <Link> uses our mock as well.
jest.mock('next/dist/client/router', () => require('next/router'));
// Mock @moxy/next-intl.
jest.mock('@moxy/next-intl', () => ({
withIntlApp: () => (App) => App,
getIntlProps: () => ({
intl: {
messages: {},
},
}),
}));