|
1 | 1 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
2 | 2 |
|
3 | 3 | import { fireEvent, render, screen, waitFor } from "@testing-library/react"; |
4 | | -import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
| 4 | +import { beforeEach, describe, expect, it, vi } from "vitest"; |
5 | 5 |
|
6 | 6 | // ===================== |
7 | 7 | // MOCKS |
@@ -37,28 +37,31 @@ vi.mock("react-phone-number-input", () => ({ |
37 | 37 | ), |
38 | 38 | })); |
39 | 39 |
|
| 40 | +const mockNavigate = vi.fn(); |
| 41 | +vi.mock("react-router-dom", () => ({ |
| 42 | + useNavigate: () => mockNavigate, |
| 43 | +})); |
| 44 | + |
| 45 | +const mockApiPost = vi.fn(); |
| 46 | +const mockApiGet = vi.fn(); |
| 47 | +vi.mock("@/services/api", () => ({ |
| 48 | + api: { |
| 49 | + post: (...args: any[]) => mockApiPost(...args), |
| 50 | + get: (...args: any[]) => mockApiGet(...args), |
| 51 | + }, |
| 52 | +})); |
| 53 | + |
40 | 54 | import RegisterSide from "@/components/login/RegisterSide"; |
41 | 55 |
|
42 | 56 | // ===================== |
43 | 57 | // TEST SUITE |
44 | 58 | // ===================== |
45 | 59 | describe("RegisterSide", () => { |
46 | | - const originalLocation = window.location; |
47 | 60 |
|
48 | 61 | beforeEach(() => { |
49 | | - mockRegister.mockReset(); |
50 | | - |
51 | | - Object.defineProperty(window, "location", { |
52 | | - configurable: true, |
53 | | - value: { href: "" }, |
54 | | - }); |
55 | | - }); |
56 | | - |
57 | | - afterEach(() => { |
58 | | - Object.defineProperty(window, "location", { |
59 | | - configurable: true, |
60 | | - value: originalLocation, |
61 | | - }); |
| 62 | + mockApiPost.mockClear(); |
| 63 | + mockApiGet.mockClear(); |
| 64 | + mockNavigate.mockClear(); |
62 | 65 | }); |
63 | 66 |
|
64 | 67 | it("renderiza formulário e alterna visibilidade da senha", () => { |
|
0 commit comments