Skip to content

Commit 784211a

Browse files
committed
fix: allow find stubbed functional component by name
1 parent 62dec1c commit 784211a

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

packages/test-utils/src/matches.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function vmMatchesName(vm, name) {
1010
// We want to mirror how Vue resolves component names in SFCs:
1111
// For example, <test-component />, <TestComponent /> and `<testComponent />
1212
// all resolve to the same component
13-
const componentName = (vm.$options && vm.$options.name) || ''
13+
const componentName = vm.name || (vm.$options && vm.$options.name) || ''
1414
return (
1515
!!name &&
1616
(componentName === name ||
@@ -56,13 +56,7 @@ export function matches(node, selector) {
5656
return element && element.matches && element.matches(selector.value)
5757
}
5858

59-
const isFunctionalSelector = isConstructor(selector.value)
60-
? selector.value.options.functional
61-
: selector.value.functional
62-
63-
const componentInstance = isFunctionalSelector
64-
? node[FUNCTIONAL_OPTIONS]
65-
: node.child
59+
const componentInstance = node[FUNCTIONAL_OPTIONS] || node.child
6660

6761
if (!componentInstance) {
6862
return false

test/specs/wrapper/find.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,27 @@ describeWithShallowAndMount('find', mountingMethod => {
257257
}
258258
})
259259

260+
it('returns functional component with name by name', () => {
261+
if (vueVersion < 2.3) {
262+
return
263+
}
264+
const TestFunctionalComponent = {
265+
render: h => h('div'),
266+
functional: true,
267+
name: 'test-functional-component'
268+
}
269+
const TestComponent = {
270+
template: '<div><test-functional-component /></div>',
271+
components: {
272+
TestFunctionalComponent
273+
}
274+
}
275+
const wrapper = mountingMethod(TestComponent)
276+
expect(
277+
wrapper.find({ name: 'test-functional-component' }).exists()
278+
).toEqual(true)
279+
})
280+
260281
it('returns extended functional component', () => {
261282
const TestFunctionalComponent = Vue.extend({
262283
render: h => h('div'),

0 commit comments

Comments
 (0)