-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
23 lines (20 loc) · 776 Bytes
/
Copy pathvitest.setup.ts
File metadata and controls
23 lines (20 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import "@testing-library/jest-dom/vitest";
import { afterEach, beforeEach, expect, vi } from "vitest";
// Fail tests on React warnings (duplicate keys, invalid props, etc.)
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
beforeEach(() => {
consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
});
afterEach(() => {
const reactWarnings = consoleErrorSpy.mock.calls.filter(
(args: unknown[]) =>
typeof args[0] === "string" &&
(args[0].includes("Warning:") || args[0].includes("Encountered two children with the same key")),
);
consoleErrorSpy.mockRestore();
if (reactWarnings.length > 0) {
expect.fail(
`React warning detected:\n${reactWarnings.map((args: unknown[]) => args.join(" ")).join("\n")}`,
);
}
});