Skip to content

Commit 71f711b

Browse files
gustavo-lolaBenevanio
authored andcommitted
test(frontend): fix authentication mock path in register side extended test
1 parent 5505756 commit 71f711b

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

frontend/tests/unit/components/login/RegisterSide.test.tsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22

33
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";
55

66
// =====================
77
// MOCKS
@@ -37,28 +37,31 @@ vi.mock("react-phone-number-input", () => ({
3737
),
3838
}));
3939

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+
4054
import RegisterSide from "@/components/login/RegisterSide";
4155

4256
// =====================
4357
// TEST SUITE
4458
// =====================
4559
describe("RegisterSide", () => {
46-
const originalLocation = window.location;
4760

4861
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();
6265
});
6366

6467
it("renderiza formulário e alterna visibilidade da senha", () => {

0 commit comments

Comments
 (0)