Skip to content

Commit bff46f1

Browse files
committed
fix: allow find to work with any casing
1 parent 7cae57a commit bff46f1

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/test-utils/src/matches.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import {
66
import { isConstructor } from 'shared/validators'
77

88
export function vmMatchesName(vm, name) {
9+
const normalize = (name = '') => name.replace(/-/gi, '').toLowerCase()
10+
const normalizedName = normalize(name)
911
return (
10-
!!name && (vm.name === name || (vm.$options && vm.$options.name === name))
12+
!!name &&
13+
(normalize(vm.name) === normalizedName ||
14+
(vm.$options && normalize(vm.$options.name) === normalizedName))
1115
)
1216
}
1317

test/specs/wrapper/find.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,20 @@ describeWithShallowAndMount('find', mountingMethod => {
431431
)
432432
})
433433

434+
it('returns a Wrapper matching a component pascal case name in options object', () => {
435+
const wrapper = mountingMethod(ComponentWithChild)
436+
expect(wrapper.find({ name: 'TestComponent' }).name()).to.equal(
437+
'test-component'
438+
)
439+
})
440+
441+
it('returns a Wrapper matching a component camel case name in options object', () => {
442+
const wrapper = mountingMethod(ComponentWithChild)
443+
expect(wrapper.find({ name: 'testComponent' }).name()).to.equal(
444+
'test-component'
445+
)
446+
})
447+
434448
it('returns Wrapper of Vue Component matching the ref in options object', () => {
435449
const wrapper = mountingMethod(ComponentWithChild)
436450
expect(wrapper.find({ ref: 'child' }).isVueInstance()).to.equal(true)

0 commit comments

Comments
 (0)