Skip to content

Commit 38ef1d3

Browse files
committed
fix(tests): corrigindo os testes do frontend
1 parent e3a390e commit 38ef1d3

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

frontend/tests/unit/pages/App.test.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { render, screen } from "@testing-library/react";
1+
import { act, render, screen } from "@testing-library/react";
2+
import { MemoryRouter } from "react-router-dom";
23
import { describe, expect, it, vi } from "vitest";
34

45
vi.mock("@/hooks/useTheme", () => ({
@@ -47,7 +48,22 @@ import App from "@/App";
4748

4849
describe("App", () => {
4950
it("renderiza painel principal", () => {
50-
render(<App />);
51-
expect(screen.getByAltText("Painel de Vagas")).toBeInTheDocument();
51+
vi.useFakeTimers();
52+
53+
try {
54+
render(
55+
<MemoryRouter initialEntries={["/"]}>
56+
<App />
57+
</MemoryRouter>
58+
);
59+
60+
act(() => {
61+
vi.advanceTimersByTime(2000);
62+
});
63+
64+
expect(screen.getAllByAltText("Painel de Vagas").length).toBeGreaterThan(0);
65+
} finally {
66+
vi.useRealTimers();
67+
}
5268
});
5369
});

frontend/vitest.setup.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,32 @@ if (!window.matchMedia) {
1414
dispatchEvent: () => false,
1515
}),
1616
});
17+
}
18+
19+
if (!window.IntersectionObserver) {
20+
class MockIntersectionObserver implements IntersectionObserver {
21+
scrollMargin: string | undefined;
22+
readonly root: Element | Document | null = null;
23+
readonly rootMargin = "0px";
24+
readonly thresholds: ReadonlyArray<number> = [0];
25+
26+
disconnect(): void {}
27+
observe(): void {}
28+
unobserve(): void {}
29+
takeRecords(): IntersectionObserverEntry[] {
30+
return [];
31+
}
32+
}
33+
34+
Object.defineProperty(window, "IntersectionObserver", {
35+
writable: true,
36+
configurable: true,
37+
value: MockIntersectionObserver,
38+
});
39+
40+
Object.defineProperty(globalThis, "IntersectionObserver", {
41+
writable: true,
42+
configurable: true,
43+
value: MockIntersectionObserver,
44+
});
1745
}

0 commit comments

Comments
 (0)