-
Notifications
You must be signed in to change notification settings - Fork 668
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
Changes from 5 commits
bff46f1
83ee6c1
82bd743
8607c28
1718005
b3e2b92
0472aa4
e8f3266
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,20 @@ import { | |
FUNCTIONAL_OPTIONS | ||
} from 'shared/consts' | ||
import { isConstructor } from 'shared/validators' | ||
import { capitalize, camelize } from 'shared/util' | ||
|
||
export function vmMatchesName(vm, name) { | ||
function vmMatchesName(vm, name) { | ||
console.log(name) | ||
console.log(vm.$options.name) | ||
return ( | ||
!!name && (vm.name === name || (vm.$options && vm.$options.name === name)) | ||
!!name && ( | ||
vm.name === name || | ||
(vm.$options && vm.$options.name === name) || | ||
vm.name === capitalize(name) || | ||
vm.$options && vm.$options.name === capitalize(name) || | ||
vm.$options && vm.$options.name && vm.$options.name === capitalize(camelize(name)) || | ||
vm.$options && vm.$options.name && capitalize(camelize(vm.$options.name)) === name | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a proposal, lets save the vm.$options.name to a variable, something like const componentName = vm.$options && vm.$options.name || '' then we can easily reduce those those lines. Yes it will use a bit more memory, but for readability sake I think it makes sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add comments for each of the conditionals? Eg what use case each line is handling? A 7 line if statement is hard to grok easily. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep agreed, I'll make these changes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dobromir-hristov I am not sure on the difference between We should check the source code for Vue and see if we can figure out the difference. Regarding your comment about the extra variable - I agree, that is more readable. I updated it the code. @JessicaSachs I added some comments explaining why we do each of the matches. What do you think? If you think you can make the comment clearer, you can add some commits or I can add some if you leave an updated comment here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also gave a quick search and did not see |
||
) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -431,6 +431,33 @@ describeWithShallowAndMount('find', mountingMethod => { | |||||
) | ||||||
}) | ||||||
|
||||||
it('returns a Wrapper matching a camelCase name option and a Pascal Case component name ', () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const component = { | ||||||
name: 'CamelCase', | ||||||
render: h => h('div') | ||||||
} | ||||||
const wrapper = mountingMethod(component) | ||||||
expect(wrapper.find({ name: 'camelCase' }).name()).to.equal('CamelCase') | ||||||
}) | ||||||
|
||||||
it('returns a Wrapper matching a kebab-case name option and a Pascal Case component name ', () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const component = { | ||||||
name: 'CamelCase', | ||||||
render: h => h('div') | ||||||
} | ||||||
const wrapper = mountingMethod(component) | ||||||
expect(wrapper.find({ name: 'camel-case' }).name()).to.equal('CamelCase') | ||||||
}) | ||||||
|
||||||
it('returns a Wrapper matching a Pascal Case name option and a kebab-casecomponent name ', () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const component = { | ||||||
name: 'camel-case', | ||||||
render: h => h('div') | ||||||
} | ||||||
const wrapper = mountingMethod(component) | ||||||
expect(wrapper.find({ name: 'CamelCase' }).name()).to.equal('camel-case') | ||||||
}) | ||||||
|
||||||
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) | ||||||
|
@@ -441,7 +468,7 @@ describeWithShallowAndMount('find', mountingMethod => { | |||||
const wrapper = mountingMethod(compiled) | ||||||
const a = wrapper.find('a') | ||||||
const message = | ||||||
'[vue-test-utils]: $ref selectors can only be used on Vue component wrappers' | ||||||
'[vue-test-utils]: $ref selectors can used on Vue component wrappers' | ||||||
dobromir-hristov marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
const fn = () => a.find({ ref: 'foo' }) | ||||||
expect(fn) | ||||||
.to.throw() | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some debugging stuff over here! ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want a lint rule for no console log? We do this at work. Same for debugger statements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its OK to have one yeah :) With the new linting on commit, it will warn you.