Skip to content

Commit 2b1e5eb

Browse files
committed
Use happy-dom instead of jsdom.
1 parent 3162d89 commit 2b1e5eb

File tree

7 files changed

+28
-7
lines changed

7 files changed

+28
-7
lines changed

bun.lock

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
"@testing-library/jest-dom": "^6.1.4",
143143
"@testing-library/react": "^16.3.0",
144144
"@types/babel__core": "^7.20.5",
145+
"@types/bun": "^1.2.14",
145146
"@types/react": "^18.2.0",
146147
"@types/react-test-renderer": "^18.0.0",
147148
"@vitejs/plugin-react": "^4.0.4",
@@ -150,8 +151,8 @@
150151
"copyfiles": "^2.4.1",
151152
"eslint": "^7.19.0",
152153
"eslint-plugin-react-hooks": "^4.6.2",
154+
"happy-dom": "^17.4.7",
153155
"husky": "^4.3.0",
154-
"jsdom": "^22.1.0",
155156
"path-to-regexp": "^6.2.1",
156157
"preact": "^10.23.2",
157158
"preact-render-to-string": "^6.5.9",

packages/wouter-preact/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ export default defineProject({
55
plugins: [preact()],
66
test: {
77
name: "wouter-preact",
8-
environment: "jsdom",
8+
environment: "happy-dom",
99
},
1010
});

packages/wouter/test/link.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ describe("<Link />", () => {
163163

164164
fireEvent.click(getByTestId("link"));
165165
expect(location.pathname).toBe("/goo-baz");
166-
expect(history.state).toBe(testState);
166+
expect(history.state).toStrictEqual(testState);
167167
});
168168

169169
it("can be configured to use custom href formatting", () => {

packages/wouter/test/redirect.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ it("supports history state", () => {
6666
const { unmount } = render(<Redirect to="/users" state={testState} />);
6767

6868
expect(location.pathname).toBe("/users");
69-
expect(history.state).toBe(testState);
69+
expect(history.state).toStrictEqual(testState);
7070
unmount();
7171
});
7272

packages/wouter/test/use-browser-location.test.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,16 @@ describe("`value` first argument", () => {
4747
history.back();
4848
});
4949

50-
await waitFor(() => expect(result.current[0]).toBe("/"));
50+
// Workaround for happy-dom: manually dispatch popstate event
51+
// happy-dom doesn't fully implement history.back() popstate events
52+
act(() => {
53+
const popstateEvent = new PopStateEvent("popstate", {
54+
state: history.state,
55+
});
56+
window.dispatchEvent(popstateEvent);
57+
});
58+
59+
await waitFor(() => expect(result.current[0]).toBe("/"), { timeout: 1000 });
5160
unmount();
5261
});
5362

packages/wouter/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ export default defineProject({
66
test: {
77
name: "wouter-react",
88
setupFiles: "./setup-vitest.ts",
9-
environment: "jsdom",
9+
environment: "happy-dom",
1010
},
1111
});

0 commit comments

Comments
 (0)