From 512883d95590c8fc229b88f1839b81eddfe89c39 Mon Sep 17 00:00:00 2001 From: Valentin Yushkevich Date: Wed, 2 Dec 2026 12:49:02 +0300 Subject: [PATCH 1/2] docs(api): fix the findComponent example with CSS selectors --- docs/api/index.md | 8 ++++---- docs/fr/api/index.md | 8 ++++---- docs/zh/api/index.md | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/api/index.md b/docs/api/index.md index 545884761..d2dd8ae98 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -1267,13 +1267,13 @@ const RootComponent = { template: '' } const wrapper = mount(RootComponent) -const rootByCss = wrapper.findComponent('.root') // => finds Root -expect(rootByCss.vm.$options.name).toBe('Root') +const rootByCss = wrapper.findComponent('.root') // => finds Child +expect(rootByCss.vm.$options.name).toBe('Child') const childByCss = wrapper.findComponent('.child') -expect(childByCss.vm.$options.name).toBe('Root') // => still Root +expect(childByCss.vm.$options.name).toBe('Child') // => still Child ``` -The reason for such behavior is that `RootComponent` and `ChildComponent` are sharing same DOM node and only first matching component is included for each unique DOM node +The reason for such behavior is that `RootComponent` and `ChildComponent` are sharing same DOM node and only one component is returned for each unique DOM node: on the root element of the mounted component, it is the component rendered at the root (here `ChildComponent`), elsewhere it is the first matching component. ::: :::info WrapperLike type when using CSS selector diff --git a/docs/fr/api/index.md b/docs/fr/api/index.md index 66df618ff..2a40b4e4d 100644 --- a/docs/fr/api/index.md +++ b/docs/fr/api/index.md @@ -1213,13 +1213,13 @@ const RootComponent = { template: '', }; const wrapper = mount(RootComponent); -const rootByCss = wrapper.findComponent('.root'); // => trouve Root -expect(rootByCss.vm.$options.name).toBe('Root'); +const rootByCss = wrapper.findComponent('.root'); // => trouve Child +expect(rootByCss.vm.$options.name).toBe('Child'); const childByCss = wrapper.findComponent('.child'); -expect(childByCss.vm.$options.name).toBe('Root'); // => toujours Root +expect(childByCss.vm.$options.name).toBe('Child'); // => toujours Child ``` -La raison de ce comportement est que `RootComponent` et `ChildComponent` partagent le même nœud DOM et que seul le premier composant correspondant est inclus pour chaque nœud DOM unique. +La raison de ce comportement est que `RootComponent` et `ChildComponent` partagent le même nœud DOM et qu'un seul composant est retourné pour chaque nœud DOM unique : sur l'élément racine du composant monté, c'est le composant rendu à la racine (ici `ChildComponent`), ailleurs c'est le premier composant correspondant. ::: :::info Type WrapperLike en utilisant un sélecteur CSS diff --git a/docs/zh/api/index.md b/docs/zh/api/index.md index 5255ae644..c710de054 100644 --- a/docs/zh/api/index.md +++ b/docs/zh/api/index.md @@ -1214,13 +1214,13 @@ const RootComponent = { template: '' } const wrapper = mount(RootComponent) -const rootByCss = wrapper.findComponent('.root') // => finds Root -expect(rootByCss.vm.$options.name).toBe('Root') +const rootByCss = wrapper.findComponent('.root') // => finds Child +expect(rootByCss.vm.$options.name).toBe('Child') const childByCss = wrapper.findComponent('.child') -expect(childByCss.vm.$options.name).toBe('Root') // => still Root +expect(childByCss.vm.$options.name).toBe('Child') // => still Child ``` -这种行为的原因是 `RootComponent` 和 `ChildComponent` 共享相同的 DOM 节点,并且每个唯一的 DOM 节点只包含第一个匹配的组件。 +这种行为的原因是 `RootComponent` 和 `ChildComponent` 共享相同的 DOM 节点,并且每个唯一的 DOM 节点只返回一个组件:在已挂载组件的根元素上,返回的是在根部渲染的组件 (此处为 `ChildComponent`),在其他位置返回的是第一个匹配的组件。 ::: :::info 使用 CSS 选择器时的 WrapperLike 类型 From 1163436bd5780c5fe1696fe960150ef7dfa2ce14 Mon Sep 17 00:00:00 2001 From: Valentin Yushkevich Date: Thu, 3 Dec 2026 07:39:31 +0300 Subject: [PATCH 2/2] docs(api): refer to the wrapper searched from --- docs/api/index.md | 2 +- docs/fr/api/index.md | 2 +- docs/zh/api/index.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/api/index.md b/docs/api/index.md index d2dd8ae98..97200c9f1 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -1273,7 +1273,7 @@ const childByCss = wrapper.findComponent('.child') expect(childByCss.vm.$options.name).toBe('Child') // => still Child ``` -The reason for such behavior is that `RootComponent` and `ChildComponent` are sharing same DOM node and only one component is returned for each unique DOM node: on the root element of the mounted component, it is the component rendered at the root (here `ChildComponent`), elsewhere it is the first matching component. +The reason for such behavior is that `RootComponent` and `ChildComponent` are sharing same DOM node and only one component is returned for each unique DOM node: on the root element of the wrapper you're searching from, it is the component rendered at the root (here `ChildComponent`), elsewhere it is the first matching component. ::: :::info WrapperLike type when using CSS selector diff --git a/docs/fr/api/index.md b/docs/fr/api/index.md index 2a40b4e4d..68a5c62d9 100644 --- a/docs/fr/api/index.md +++ b/docs/fr/api/index.md @@ -1219,7 +1219,7 @@ const childByCss = wrapper.findComponent('.child'); expect(childByCss.vm.$options.name).toBe('Child'); // => toujours Child ``` -La raison de ce comportement est que `RootComponent` et `ChildComponent` partagent le même nœud DOM et qu'un seul composant est retourné pour chaque nœud DOM unique : sur l'élément racine du composant monté, c'est le composant rendu à la racine (ici `ChildComponent`), ailleurs c'est le premier composant correspondant. +La raison de ce comportement est que `RootComponent` et `ChildComponent` partagent le même nœud DOM et qu'un seul composant est retourné pour chaque nœud DOM unique : sur l'élément racine du wrapper à partir duquel vous cherchez, c'est le composant rendu à la racine (ici `ChildComponent`), ailleurs c'est le premier composant correspondant. ::: :::info Type WrapperLike en utilisant un sélecteur CSS diff --git a/docs/zh/api/index.md b/docs/zh/api/index.md index c710de054..6639dd655 100644 --- a/docs/zh/api/index.md +++ b/docs/zh/api/index.md @@ -1220,7 +1220,7 @@ const childByCss = wrapper.findComponent('.child') expect(childByCss.vm.$options.name).toBe('Child') // => still Child ``` -这种行为的原因是 `RootComponent` 和 `ChildComponent` 共享相同的 DOM 节点,并且每个唯一的 DOM 节点只返回一个组件:在已挂载组件的根元素上,返回的是在根部渲染的组件 (此处为 `ChildComponent`),在其他位置返回的是第一个匹配的组件。 +这种行为的原因是 `RootComponent` 和 `ChildComponent` 共享相同的 DOM 节点,并且每个唯一的 DOM 节点只返回一个组件:在你进行搜索的包装器的根元素上,返回的是在根部渲染的组件 (此处为 `ChildComponent`),在其他位置返回的是第一个匹配的组件。 ::: :::info 使用 CSS 选择器时的 WrapperLike 类型