-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvitest.setup.ts
31 lines (27 loc) · 899 Bytes
/
vitest.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
import { afterEach, vi, beforeEach, Mock } from 'vitest';
import { cleanup } from '@testing-library/react';
import resizeObserverPolyfill from 'resize-observer-polyfill';
import { useRouter, useSearchParams, useParams, usePathname } from 'next/navigation';
// runs a cleanup after each test case (e.g. clearing jsdom)
afterEach(() => {
cleanup();
});
global.ResizeObserver = resizeObserverPolyfill;
vi.mock('next/navigation', () => ({
useRouter: vi.fn(),
useSearchParams: vi.fn(),
usePathname: vi.fn(),
useParams: vi.fn()
}));
beforeEach(() => {
(useSearchParams as Mock).mockImplementation(() => ({
get: vi.fn(() => null)
}));
(useRouter as Mock).mockImplementation(() => ({
push: vi.fn(() => null)
}));
(usePathname as Mock).mockImplementation(() => '/');
(useParams as Mock).mockImplementation(() => ({
locale: 'en'
}));
});