mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
fix(work-orders): type-safe FormData test and Node harness stability
(cherry picked from commit a30326aa491e72b2b95eb1f55d77d14ef9004ec8)
This commit is contained in:
parent
175682e229
commit
729deff897
1 changed files with 34 additions and 1 deletions
|
|
@ -1,11 +1,44 @@
|
|||
import "@testing-library/jest-dom/vitest";
|
||||
import { cleanup } from "@testing-library/react";
|
||||
import { afterEach } from "vitest";
|
||||
import { afterEach, vi } from "vitest";
|
||||
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
});
|
||||
|
||||
function localStorageIsUsable(): boolean {
|
||||
try {
|
||||
const probe = "__vitest_ls_probe__";
|
||||
globalThis.localStorage.setItem(probe, "1");
|
||||
const ok = globalThis.localStorage.getItem(probe) === "1";
|
||||
globalThis.localStorage.removeItem(probe);
|
||||
return ok;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Node 25+ / some harnesses lack a stable localStorage — provide an in-memory mock when needed.
|
||||
if (!localStorageIsUsable()) {
|
||||
const store = new Map<string, string>();
|
||||
vi.stubGlobal("localStorage", {
|
||||
getItem: (key: string) => store.get(key) ?? null,
|
||||
setItem: (key: string, value: string) => {
|
||||
store.set(key, String(value));
|
||||
},
|
||||
removeItem: (key: string) => {
|
||||
store.delete(key);
|
||||
},
|
||||
clear: () => {
|
||||
store.clear();
|
||||
},
|
||||
get length() {
|
||||
return store.size;
|
||||
},
|
||||
key: (index: number) => [...store.keys()][index] ?? null,
|
||||
});
|
||||
}
|
||||
|
||||
Object.defineProperty(window, "matchMedia", {
|
||||
writable: true,
|
||||
value: (query: string) => ({
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue