generated from 202306-NEA-DZ-FEW/capstone-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjest.setup.js
58 lines (52 loc) · 1.54 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { useRouter } from "next/router";
import "@testing-library/jest-dom/extend-expect";
// the next test is common between diferent components
// it mocks firebase diferent functions and useRouter, and useTranslation
// sendPasswordResetEmail is mocked to always return a resolved promise.
// useRoutere is mocked to exist and return an object
// useTranslation is mocked to exist and return an object
jest.mock("@/util/firebase", () => {
return {
auth: jest.fn(() => ({
sendPasswordResetEmail: jest.fn(() =>
Promise.resolve("Password reset email sent.")
),
})),
initializeApp: jest.fn(),
getAuth: jest.fn(),
};
});
jest.mock("@/context/state.js", () => {
return {
useAppcontext: jest.fn(() => {
return {
setBookingInfos: jest.fn(() => {}),
user: jest.fn(() => {}),
blogs: [{ title: "blog 1" }, { title: "blog 2" }],
};
}),
};
});
jest.mock("next/navigation", () => {
return {
__esModule: true,
useRouter: jest.fn(),
usePathname: jest.fn(() => "/home"),
useSearchParams: jest.fn(),
};
});
jest.mock("next/router", () => ({
useRouter: jest.fn(),
}));
// In your test setup
useRouter.mockImplementation(() => ({
push: jest.fn(),
prefetch: jest.fn(),
// Add any other router methods you need
}));
jest.mock("next-i18next", () => ({
useTranslation: () => ({ t: (key) => key }),
}));
jest.mock("axios", () => ({
axios: jest.fn(),
}));