Skip to content

Commit 1718005

Browse files
committed
fix: cover both kebab and camel cases
1 parent 8607c28 commit 1718005

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

packages/test-utils/src/matches.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ import {
44
FUNCTIONAL_OPTIONS
55
} from 'shared/consts'
66
import { isConstructor } from 'shared/validators'
7-
import { capitalize } from 'shared/util'
7+
import { capitalize, camelize } from 'shared/util'
88

99
function vmMatchesName(vm, name) {
10+
console.log(name)
11+
console.log(vm.$options.name)
1012
return (
1113
!!name && (
12-
vm.name === name ||
14+
vm.name === name ||
1315
(vm.$options && vm.$options.name === name) ||
1416
vm.name === capitalize(name) ||
15-
vm.$options && vm.$options.name === capitalize(name)
17+
vm.$options && vm.$options.name === capitalize(name) ||
18+
vm.$options && vm.$options.name && vm.$options.name === capitalize(camelize(name)) ||
19+
vm.$options && vm.$options.name && capitalize(camelize(vm.$options.name)) === name
1620
)
1721
)
1822
}

test/specs/wrapper/find.spec.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,24 @@ describeWithShallowAndMount('find', mountingMethod => {
440440
expect(wrapper.find({ name: 'camelCase' }).name()).to.equal('CamelCase')
441441
})
442442

443+
it('returns a Wrapper matching a kebab-case name option and a Pascal Case component name ', () => {
444+
const component = {
445+
name: 'CamelCase',
446+
render: h => h('div')
447+
}
448+
const wrapper = mountingMethod(component)
449+
expect(wrapper.find({ name: 'camel-case' }).name()).to.equal('CamelCase')
450+
})
451+
452+
it('returns a Wrapper matching a Pascal Case name option and a kebab-casecomponent name ', () => {
453+
const component = {
454+
name: 'camel-case',
455+
render: h => h('div')
456+
}
457+
const wrapper = mountingMethod(component)
458+
expect(wrapper.find({ name: 'CamelCase' }).name()).to.equal('camel-case')
459+
})
460+
443461
it('returns Wrapper of Vue Component matching the ref in options object', () => {
444462
const wrapper = mountingMethod(ComponentWithChild)
445463
expect(wrapper.find({ ref: 'child' }).isVueInstance()).to.equal(true)
@@ -450,7 +468,7 @@ describeWithShallowAndMount('find', mountingMethod => {
450468
const wrapper = mountingMethod(compiled)
451469
const a = wrapper.find('a')
452470
const message =
453-
'[vue-test-utils]: $ref selectors can only be used on Vue component wrappers'
471+
'[vue-test-utils]: $ref selectors can used on Vue component wrappers'
454472
const fn = () => a.find({ ref: 'foo' })
455473
expect(fn)
456474
.to.throw()

0 commit comments

Comments
 (0)