Skip to content

Commit e31127f

Browse files
committed
⬆️ dependency upgrade. ✅ update tests.
1 parent f3e0830 commit e31127f

5 files changed

Lines changed: 21 additions & 17 deletions

File tree

@simulcast/preact/tests/useBroadcast.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import { broadcast, type EventRegistry } from "@simulcast/core";
33
import { useBroadcast } from "@simulcast/preact";
44
import { assertStrictEquals } from "@std/assert";
5-
import { type ComponentProps, render, type TargetedMouseEvent } from "preact";
6-
import { useState } from "preact/hooks";
75
import { mockDOM } from "@test/mockDOM.ts";
86
import { timeout } from "@test/timeout.ts";
7+
import { type ComponentProps, render, type TargetedMouseEvent } from "preact";
8+
import { useState } from "preact/hooks";
99

1010
const CountComponent = (properties: ComponentProps<"button">) => {
1111
const [count, setCount] = useState(0);
@@ -78,9 +78,9 @@ Deno.test(
7878
) as HTMLButtonElement;
7979

8080
addButton.click(); // Click button that will re-render once
81-
await timeout();
81+
await timeout(10);
8282
addButton.click(); // Click button that will re-render twice
83-
await timeout();
83+
await timeout(10);
8484
broadcastButton.click(); // Click broadcast button once
8585
assertStrictEquals(state.calledTimes, 1); // State should be updated once
8686
assertStrictEquals(addButton.textContent, "2"); // Even when it re-rendered twice

@simulcast/react/tests/useBroadcast.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import { broadcast, type EventRegistry } from "@simulcast/core";
33
import { useBroadcast } from "@simulcast/react";
44
import { assertStrictEquals } from "@std/assert";
5-
import { type ComponentProps, type MouseEvent, useState } from "react";
6-
import { createRoot } from "react-dom/client";
75
import { mockDOM } from "@test/mockDOM.ts";
86
import { timeout } from "@test/timeout.ts";
7+
import { type ComponentProps, type MouseEvent, useState } from "react";
8+
import { createRoot } from "react-dom/client";
99

1010
const CountComponent = (properties: ComponentProps<"button">) => {
1111
const [count, setCount] = useState(0);
@@ -69,7 +69,7 @@ Deno.test(
6969
),
7070
);
7171

72-
await timeout(3);
72+
await timeout(10);
7373

7474
const addButton = document.querySelector<HTMLButtonElement>(
7575
"button.add",
@@ -131,7 +131,7 @@ Deno.test("Broadcast's on handler is removed when unmounted", async () => {
131131

132132
root.render(<App />);
133133

134-
await timeout(1);
134+
await timeout(10);
135135

136136
const toggleButton = document.querySelector<HTMLButtonElement>(
137137
"button.toggle",

deno.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
"@types/react": "npm:@types/react@^19.2.7",
4545
"@types/react-dom": "npm:@types/react-dom@^19.2.3",
4646
"@vue/test-utils": "npm:@vue/test-utils@^2.4.6",
47-
"linkedom": "npm:linkedom@^0.18.12",
48-
"preact": "npm:preact@~10.27.2",
49-
"preact-render-to-string": "npm:preact-render-to-string@~6.6.3",
50-
"react": "npm:react@^19.2.0",
51-
"react-dom": "npm:react-dom@^19.2.0",
47+
"happy-dom": "npm:happy-dom@^20.0.11",
48+
"preact": "npm:preact@~10.28.0",
49+
"preact-render-to-string": "npm:preact-render-to-string@~6.6.4",
50+
"react": "npm:react@^19.2.3",
51+
"react-dom": "npm:react-dom@^19.2.3",
5252
"vue": "npm:vue@^3.5.25"
5353
},
5454
"lint": {

test/mockDOM.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { parseHTML } from "linkedom/worker";
1+
// deno-coverage-ignore-file
2+
import { Window } from "happy-dom";
23

34
Error.stackTraceLimit = Infinity;
45

@@ -8,7 +9,7 @@ const properties = [
89
"SVGElement",
910
"document",
1011
"window",
11-
] as const satisfies ReadonlyArray<keyof ReturnType<typeof parseHTML>>;
12+
] as const satisfies ReadonlyArray<keyof InstanceType<typeof Window>>;
1213

1314
/**
1415
* Sets a global mocked DOM or resets it if it's already set.
@@ -30,10 +31,12 @@ export const mockDOM = (
3031
template?: string;
3132
} = {},
3233
): void => {
33-
const parsed = parseHTML(template);
34+
const window = new Window();
35+
36+
window.document.body.innerHTML = template;
3437

3538
properties.forEach((property) =>
36-
Object.assign(globalThis, { [property]: parsed[property] })
39+
Object.assign(globalThis, { [property]: window[property] })
3740
);
3841

3942
if (fakeTimers) {

test/setupTests.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// deno-coverage-ignore-file
12
import { mockDOM } from "./mockDOM.ts";
23

34
mockDOM();

0 commit comments

Comments
 (0)