Skip to content

fix: allow plain objects for typed event properties in trigger - #3043

Merged
cexbrayat merged 2 commits into
vuejs:mainfrom
ValentinYoushkevich:fix/trigger-typed-event-init
Nov 25, 2026
Merged

cexbrayat merged 2 commits into
vuejs:mainfrom
ValentinYoushkevich:fix/trigger-typed-event-init

Conversation

@ValentinYoushkevich

Copy link
Copy Markdown
Contributor

trigger passes its options to the event constructor. Browsers reject plain objects for typed init members, so this throws in a real browser (e.g. Vitest Browser Mode, which this repo now also runs):

await wrapper.trigger('drop', { dataTransfer: { files: [file] } })
// TypeError: Failed to construct 'DragEvent': Failed to read the 'dataTransfer'
// property from 'DragEventInit': Failed to convert value to 'DataTransfer'.

Same for clipboardData, touches/changedTouches/targetTouches and source/ports. jsdom accepts these, but it also rejects a plain object as relatedTarget or view.

If the constructor throws, the event is now created without the plain object and array values it rejects, and those are then defined on the event. Otherwise nothing changes: native values (a real DataTransfer, an element as relatedTarget) still go through the constructor, and a wrapper passed by mistake as relatedTarget still throws.

Real tests doing this: element-plus, tdesign-vue-next, activist.

Playground (2.6.0): play.vuejs.org

@netlify

netlify Bot commented Nov 19, 2026

Copy link
Copy Markdown

👷 Deploy request for vue-test-utils-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 6722273

@pkg-pr-new

pkg-pr-new Bot commented Nov 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@vue/test-utils@3043

commit: 6722273

@cexbrayat
cexbrayat merged commit a47799a into vuejs:main Nov 25, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants