Skip to content

Commit af7a4c5

Browse files
committed
Merge branch 'master' into feature/add-warning
2 parents 9e67a44 + b1ff235 commit af7a4c5

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/utils/find.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ function findAllVNodes(
111111
if (node.component) {
112112
// match children of the wrapping component
113113
aggregateChildren(nodes, node.component.subTree.children)
114+
aggregateChildren(nodes, [node.component.subTree])
114115
}
115116
if (node.suspense) {
116117
// match children if component is Suspense
@@ -123,7 +124,7 @@ function findAllVNodes(
123124
aggregateChildren(nodes, fallbackTree.children)
124125
}
125126
}
126-
if (matches(node, selector)) {
127+
if (matches(node, selector) && !matchingNodes.includes(node)) {
127128
matchingNodes.push(node)
128129
}
129130
}

tests/findComponent.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,29 @@ describe('findComponent', () => {
226226
expect(compB[0].vm.$el.querySelector('.content').innerHTML).toBe('1')
227227
expect(compB[0].vm.$el.querySelector('.content').textContent).toBe('1')
228228
})
229+
230+
// https://github.com/vuejs/vue-test-utils-next/pull/188
231+
const slotComponent = defineComponent({
232+
name: 'slotA',
233+
template: '<div><slot /><slot name="b" /></div>'
234+
})
235+
const SlotMain = defineComponent({
236+
name: 'SlotMain',
237+
template:
238+
'<slot-component><comp-b /><comp-b /><comp-b /><comp-c v-slot:b /></slot-component>',
239+
components: { slotComponent, compB, compC }
240+
})
241+
const SlotApp = defineComponent({
242+
name: 'SlotApp',
243+
template: `<slot-main />`,
244+
components: { SlotMain }
245+
})
246+
247+
it('finds components with slots which will be compiled to `{ default: () => [children] }`', () => {
248+
const wrapper = mount(SlotApp)
249+
expect(wrapper.findComponent(slotComponent).exists()).toBe(true)
250+
expect(wrapper.findComponent(compB).exists()).toBe(true)
251+
expect(wrapper.findComponent(compC).exists()).toBe(true)
252+
expect(wrapper.findComponent(SlotMain).exists()).toBe(true)
253+
})
229254
})

0 commit comments

Comments
 (0)