-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjest.setup.ts
More file actions
35 lines (30 loc) · 1.08 KB
/
jest.setup.ts
File metadata and controls
35 lines (30 loc) · 1.08 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
// jest.setup.ts
import { server } from "@/mocks/server";
import renderWithQueryClient from "@/utils/testRenderWithQueryClient";
import "@testing-library/jest-dom";
// 모든 테스트가 시작하기 전 MSW 서버를 시작합니다.
beforeAll(() => server.listen());
// 이전 테스트의 모의 응답이 다음 테스트에 영향을 주지 않도록 이전 테스트에서 설정된 핸들러를 초기화합니다.
afterEach(() => server.resetHandlers());
// 모든 테스트가 완료된 후에 MSW 서버를 종료합니다.
afterAll(() => server.close());
// usePathname 모킹 : mockPathname을 import하여 테스트 파일에서 경로를 동적으로 설정할 수 있습니다.
const mockNavigation = {
pathname: "/",
};
jest.mock("next/navigation", () => ({
// useRouter 모킹
useRouter: () => ({
push: jest.fn(),
replace: jest.fn(),
back: jest.fn(),
}),
usePathname: () => mockNavigation.pathname,
}));
jest.mock("next/image", () => ({
__esModule: true,
default: () => {
return "not found";
},
}));
export { mockNavigation, renderWithQueryClient };