-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Bug: test throws an error when using a MouseEvent with jsdom environment #4685
Copy link
Copy link
Closed
Description
Describe the bug
Tests fail when simulating mouse events. The tests pass when using Vitest and happy-dom, and the tests pass when using Jest and jest-environment-dom.
Error message
FAIL test/mouse-event.test.ts > repro
TypeError: Failed to construct 'MouseEvent': member view is not of type Window.
❯ new UIEventImpl node_modules/jsdom/lib/jsdom/living/events/UIEvent-impl.js:30:15
❯ new MouseEventImpl node_modules/jsdom/lib/jsdom/living/events/MouseEvent-impl.js:9:1
❯ exports.setup node_modules/jsdom/lib/jsdom/living/generated/MouseEvent.js:59:12
❯ new MouseEvent node_modules/jsdom/lib/jsdom/living/generated/MouseEvent.js:117:22
❯ eval test/mouse-event.test.ts:9:17
7|
8| const onClick = vi.fn();
9| button.onclick = onClick;
| ^
10|
11| document.body.append(button);
Reproduction
System Info
System:
OS: macOS 12.6.8
CPU: (10) arm64 Apple M1 Pro
Memory: 115.47 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node
Yarn: 1.22.15 - ~/.yarn/bin/yarn
npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm
pnpm: 8.10.5 - ~/.nvm/versions/node/v18.17.1/bin/pnpm
bun: 1.0.2 - ~/.bun/bin/bun
Browsers:
Chrome: 119.0.6045.199
Safari: 15.6.1
npmPackages:
@vitest/coverage-v8: ^0.34.6 => 0.34.6
@vitest/ui: ^0.34.6 => 0.34.6
vite: ^4.4.8 => 4.5.0
vitest: ^1.0.0 => 1.0.1Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels