Skip to content

Commit c3db9b2

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

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

packages/test-utils/src/matches.js

Lines changed: 2 additions & 8 deletions
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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,24 @@ describeWithShallowAndMount('find', mountingMethod => {
257257
}
258258
})
259259

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

0 commit comments

Comments
 (0)