Skip to content

Commit a9fd8b5

Browse files
committed
add missing edge case
1 parent 805a31a commit a9fd8b5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/baseWrapper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ export default abstract class BaseWrapper<ElementType extends Node>
103103
): DOMWrapper<SVGElementTagNameMap[K]>[]
104104
findAll<T extends Element>(selector: string): DOMWrapper<T>[]
105105
findAll(selector: string): DOMWrapper<Element>[] {
106-
return this.findAllDOMElements(selector, true).map(createDOMWrapper)
106+
const isRootNodeOfTemplate = this.getRootNodes()?.[0] === this.element
107+
const ignoreSelf = !isRootNodeOfTemplate || !Reflect.get(this, 'vm')
108+
return this.findAllDOMElements(selector, ignoreSelf).map(createDOMWrapper)
107109
}
108110

109111
// searching by string without specifying component results in WrapperLike object

tests/find.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,4 +357,19 @@ describe('findAll', () => {
357357

358358
expect(parent.findAll('div').length).toBe(3)
359359
})
360+
361+
// https://github.com/vuejs/test-utils/issues/1233
362+
it('finds all divs with findAll', () => {
363+
const wrapper = mount({
364+
template: `
365+
<div class="parent">
366+
<div />
367+
<div />
368+
<div />
369+
</div>
370+
`
371+
})
372+
373+
expect(wrapper.findAll('div').length).toBe(4)
374+
})
360375
})

0 commit comments

Comments
 (0)