Skip to content

fix: find elements and components inside multi-root functional components - #2971

Merged
cexbrayat merged 1 commit into
vuejs:mainfrom
ValentinYoushkevich:fix/functional-multi-root-find
Oct 15, 2026
Merged

cexbrayat merged 1 commit into
vuejs:mainfrom
ValentinYoushkevich:fix/functional-multi-root-find

Conversation

@ValentinYoushkevich

Copy link
Copy Markdown
Contributor

Follow-up to #2568 / #2579.

findComponent(Func) on a functional component returning an array gives a DOMWrapper around the fragment anchor, so:

  • html()/text() lose nested arrays and slots
  • find/findAll/get find nothing
  • findComponent/findAllComponents find nothing
const Func: FunctionalComponent = (_, { slots }) => [h('h1', 'title'), slots.default?.()]
const func = mount({ components: { Func }, template: '<div><Func><span>foo</span></Func></div>' }).findComponent(Func)
func.html()                // '<h1>title</h1>\n' (span missing)
func.find('span').exists() // false

The wrapper now collects its roots with getRootNodes() (like VueWrapper) and resolves the functional instance from the fragment anchor, reading its current subTree so results stay in sync after a re-render.

Note: like a multi-root VueWrapper, html() no longer prints <!----> for empty (null/false) roots. isVisible()/classes()/attributes()/trigger() still target the anchor.

Repro on 2.5.1: playground

…ents

findComponent on a functional component returning an array wrapped the fragment anchor, so html/text lost nested roots and find/findComponent found nothing. Collect the roots of the functional instance like VueWrapper does, reading its current subTree.
@netlify

netlify Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

❌ Deploy Preview for vue-test-utils-docs failed. Why did it fail? →

Name Link
🔨 Latest commit 02b533a
🔍 Latest deploy log https://app.netlify.com/projects/vue-test-utils-docs/deploys/6acf6c8eaddbc4634ab88d7f

@pkg-pr-new

pkg-pr-new Bot commented Oct 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 02b533a

@cexbrayat
cexbrayat merged commit c11bddd into vuejs:main Oct 15, 2026
5 of 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