Skip to content

Commit a676efc

Browse files
committed
fix solid-js/web test mock behavior
Keep the real browser exports available in tests so JSX rendering still works while delegateEvents remains safe for mocked window/document setups. Made-with: Cursor
1 parent a5da264 commit a676efc

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

test/setup.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import { vi } from "vitest";
22

3-
vi.mock("solid-js/web", () => ({
4-
isServer: false,
5-
delegateEvents: vi.fn(),
6-
getRequestEvent: () => null
7-
}));
3+
vi.mock("solid-js/web", async importOriginal => {
4+
const actual = await importOriginal<typeof import("solid-js/web")>();
5+
6+
return {
7+
...actual,
8+
delegateEvents: ((eventNames, document) => {
9+
const target = document ?? globalThis.window?.document ?? globalThis.document;
10+
if (!target) return;
11+
return actual.delegateEvents(eventNames, target);
12+
}) as typeof actual.delegateEvents,
13+
isServer: false,
14+
getRequestEvent: () => null
15+
};
16+
});

0 commit comments

Comments
 (0)