Skip to content

Allow find to work on both Pascal case and camel case #1398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/test-utils/src/matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import {
} from 'shared/consts'
import { isConstructor } from 'shared/validators'

export function vmMatchesName(vm, name) {
function vmMatchesName(vm, name) {
const lc = (name = '') => name.toLowerCase()
const lowerCaseName = lc(name)
return (
!!name && (vm.name === name || (vm.$options && vm.$options.name === name))
!!name &&
(lc(vm.name) === lowerCaseName ||
(vm.$options && lc(vm.$options.name) === lowerCaseName))
)
}

Expand Down
16 changes: 16 additions & 0 deletions test/specs/wrapper/find.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,22 @@ describeWithShallowAndMount('find', mountingMethod => {
)
})

it('returns a Wrapper matching a component camel case name in options object', () => {
const wrapper = mountingMethod(ComponentWithChild)
expect(wrapper.find({ name: 'test-Component' }).name()).to.equal(
'test-component'
)
})

it('returns a Wrapper matching a name disregarding case in options object', () => {
const component = {
name: 'CamelCase',
render: h => h('div')
}
const wrapper = mountingMethod(component)
expect(wrapper.find({ name: 'camelCase' }).name()).to.equal('CamelCase')
})

it('returns Wrapper of Vue Component matching the ref in options object', () => {
const wrapper = mountingMethod(ComponentWithChild)
expect(wrapper.find({ ref: 'child' }).isVueInstance()).to.equal(true)
Expand Down