File tree Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Expand file tree Collapse file tree 2 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,22 @@ import {
44 FUNCTIONAL_OPTIONS
55} from 'shared/consts'
66import { isConstructor } from 'shared/validators'
7+ import { capitalize , camelize } from 'shared/util'
78
8- export function vmMatchesName ( vm , name ) {
9+ function vmMatchesName ( vm , name ) {
10+ // We want to mirror how Vue resolves component names in SFCs:
11+ // For example, <test-component />, <TestComponent /> and `<testComponent />
12+ // all resolve to the same component
13+ const componentName = ( vm . $options && vm . $options . name ) || ''
914 return (
10- ! ! name && ( vm . name === name || ( vm . $options && vm . $options . name === name ) )
15+ ! ! name &&
16+ ( componentName === name ||
17+ // testComponent -> TestComponent
18+ componentName === capitalize ( name ) ||
19+ // test-component -> TestComponent
20+ componentName === capitalize ( camelize ( name ) ) ||
21+ // same match as above, but the component name vs query
22+ capitalize ( camelize ( componentName ) ) === name )
1123 )
1224}
1325
Original file line number Diff line number Diff line change @@ -431,6 +431,33 @@ describeWithShallowAndMount('find', mountingMethod => {
431431 )
432432 } )
433433
434+ it ( 'returns a Wrapper matching a camelCase name option and a Pascal Case component name ' , ( ) => {
435+ const component = {
436+ name : 'CamelCase' ,
437+ render : h => h ( 'div' )
438+ }
439+ const wrapper = mountingMethod ( component )
440+ expect ( wrapper . find ( { name : 'camelCase' } ) . name ( ) ) . to . equal ( 'CamelCase' )
441+ } )
442+
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+
434461 it ( 'returns Wrapper of Vue Component matching the ref in options object' , ( ) => {
435462 const wrapper = mountingMethod ( ComponentWithChild )
436463 expect ( wrapper . find ( { ref : 'child' } ) . isVueInstance ( ) ) . to . equal ( true )
You can’t perform that action at this time.
0 commit comments