forked from jenkinsci/pipeline-graph-view-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetupTests.ts
More file actions
33 lines (29 loc) · 967 Bytes
/
setupTests.ts
File metadata and controls
33 lines (29 loc) · 967 Bytes
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
import "@testing-library/jest-dom/vitest";
import { vi } from "vitest";
// Ensure a functional localStorage implementation for tests that persist user preferences.
if (
!("localStorage" in window) ||
typeof window.localStorage?.getItem !== "function" ||
typeof window.localStorage?.setItem !== "function"
) {
const store: Record<string, string> = {};
const localStoragePolyfill = {
getItem: (key: string) => (key in store ? store[key] : null),
setItem: (key: string, value: string) => {
store[key] = String(value);
},
removeItem: (key: string) => {
delete store[key];
},
clear: () => {
Object.keys(store).forEach((k) => delete store[k]);
},
};
// @ts-expect-error override for test environment
window.localStorage = localStoragePolyfill;
}
const IntersectionObserverMock = vi.fn(() => ({
disconnect: vi.fn(),
observe: vi.fn(),
}));
vi.stubGlobal("IntersectionObserver", IntersectionObserverMock);