Skip to content

fix: support attachTo on Vue versions before 3.5 - #2974

Merged
cexbrayat merged 2 commits into
vuejs:mainfrom
ValentinYoushkevich:fix/attach-to-vue-3-4
Oct 21, 2026
Merged

cexbrayat merged 2 commits into
vuejs:mainfrom
ValentinYoushkevich:fix/attach-to-vue-3-4

Conversation

@ValentinYoushkevich

@ValentinYoushkevich ValentinYoushkevich commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Since #2700, mount with attachTo calls app.onUnmount, which only exists since Vue 3.5, so on Vue 3.0–3.4 it throws TypeError: app.onUnmount is not a function (the peer range is vue: 3.x).

// vue 3.4.38, @vue/test-utils 2.5.1
mount(Hello, { attachTo: document.body }) // TypeError: app.onUnmount is not a function

This also breaks every render() of @testing-library/vue on these versions, as it always passes attachTo and depends on @vue/test-utils@^2.4.1.

This uses app.onUnmount when available and otherwise wraps app.unmount, so the container is still removed on unmount. I also ran the whole test suite against Vue 3.4.38: 3 tests fail on main, all pass with this change.

Repro on 2.5.1 with Vue 3.4.38: playground

app.onUnmount, used since vuejs#2700 to remove the attachTo container, only exists since Vue 3.5, so mounting with attachTo threw on older versions while the peer range is vue 3.x. Wrap app.unmount instead.
@netlify

netlify Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for vue-test-utils-docs ready!

Name Link
🔨 Latest commit 35d458b
🔍 Latest deploy log https://app.netlify.com/projects/vue-test-utils-docs/deploys/6ad8384525486f817b76fb92
😎 Deploy Preview https://deploy-preview-2974--vue-test-utils-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 35d458b

Comment thread src/mount.ts Outdated
@cexbrayat
cexbrayat merged commit 9300567 into vuejs:main Oct 21, 2026
9 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