forked from reach/reach-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupTests.ts
43 lines (38 loc) · 1.12 KB
/
setupTests.ts
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
import "vitest-axe/extend-expect";
import "vitest-dom/extend-expect";
import * as axeMatchers from "vitest-axe/matchers";
import * as domMatchers from "vitest-dom/matchers";
import { beforeAll, expect, vi } from "vitest";
import moduleAlias from "module-alias";
import { alias } from "./alias";
import { reactVersion } from "./env";
Object.entries(alias).forEach(([aliasFrom, aliasTo]) => {
moduleAlias.addAlias(aliasFrom, aliasTo);
});
if (reactVersion === 16) {
vi.spyOn(globalThis.performance, "mark").mockImplementation(() => ({
detail: undefined,
duration: 0,
entryType: "",
name: "",
startTime: 0,
toJSON: () => "",
}));
} else if (reactVersion === 18) {
// @ts-ignore: @see https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#configuring-your-testing-environment
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
}
expect.extend(axeMatchers);
expect.extend(domMatchers);
beforeAll(() => {
vi.mock("@reach/auto-id", () => {
return {
useId: (fallback: string) => fallback || "REACH-ID",
};
});
vi.mock("@reach/rect", () => {
return {
useRect: () => ({ height: 1, width: 1, x: 0, y: 0 }),
};
});
});