Skip to content

Commit 54e7cf9

Browse files
committed
clean code and move test case to findComponent
1 parent d9d2efe commit 54e7cf9

File tree

3 files changed

+26
-67
lines changed

3 files changed

+26
-67
lines changed

src/utils/find.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,11 @@ function findAllVNodes(
124124
aggregateChildren(nodes, fallbackTree.children)
125125
}
126126
}
127-
if (matches(node, selector) && matchingNodes.indexOf(node) < 0) {
127+
if (matches(node, selector) && !matchingNodes.includes(node)) {
128128
matchingNodes.push(node)
129129
}
130130
}
131131

132-
// console.log(matchingNodes)
133-
134132
return matchingNodes
135133
}
136134

tests/findAllComponentsInSubTree.spec.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

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 compile 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)