-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvitest.setup.ts
More file actions
66 lines (56 loc) · 1.56 KB
/
vitest.setup.ts
File metadata and controls
66 lines (56 loc) · 1.56 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import "@testing-library/jest-dom";
import { server } from "./src/mocks/server";
import { queryClient } from "./src/utils/test-utils";
import { cleanup } from "@testing-library/react";
import { useEffect } from "react";
import { ApngProps } from "@diamondlightsource/ui-components";
export const mockToast = vi.fn();
beforeEach(() => server.listen());
afterEach(() => {
server.resetHandlers();
queryClient.clear();
mockToast.mockClear();
cleanup();
});
afterAll(() => {
server.close();
vi.restoreAllMocks();
});
vi.mock("@chakra-ui/react", async (importOriginal) => {
const actual = await importOriginal<any>();
return {
...actual,
createStandaloneToast: () => ({ toast: mockToast }),
useToast: () => mockToast,
};
});
vi.mock("@diamondlightsource/ui-components", async (importOriginal) => {
const actual = await importOriginal<any>();
return {
...actual,
APNGViewer: ({ onFrameCountChanged, src }: ApngProps) => {
useEffect(() => {
if (onFrameCountChanged) {
onFrameCountChanged(3);
}
}, [onFrameCountChanged]);
return src;
},
};
});
class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
}
window.ENV = {
API_URL: "http://localhost/",
AUTH_URL: "http://localhost/auth/",
DEV_CONTACT: "guilherme.de-freitas@diamond.ac.uk",
ENVIRONMENT: "production",
FEEDBACK_URL: "true",
REPROCESSING_ENABLED: true
}
global.window.scrollTo = () => {}
global.ResizeObserver = ResizeObserver;
global.structuredClone = (val: Record<string, any>) => JSON.parse(JSON.stringify(val));