@@ -73,12 +73,12 @@ export default class Wrapper implements BaseWrapper {
7373 contains ( selector : Selector ) {
7474 const selectorType = getSelectorTypeOrThrow ( selector , 'contains' )
7575
76- if ( selectorType === selectorTypes . VUE_COMPONENT ) {
76+ if ( selectorType === selectorTypes . NAME_SELECTOR || selectorType === selectorTypes . VUE_COMPONENT ) {
7777 const vm = this . vm || this . vnode . context . $root
78- return findVueComponents ( vm , selector . name ) . length > 0 || this . is ( selector )
78+ return findVueComponents ( vm , selector , selector ) . length > 0 || this . is ( selector )
7979 }
8080
81- if ( selectorType === selectorTypes . OPTIONS_OBJECT ) {
81+ if ( selectorType === selectorTypes . REF_SELECTOR ) {
8282 if ( ! this . vm ) {
8383 throwError ( '$ref selectors can only be used on Vue component wrappers' )
8484 }
@@ -228,19 +228,19 @@ export default class Wrapper implements BaseWrapper {
228228 */
229229 find ( selector : Selector ) : Wrapper | ErrorWrapper | VueWrapper {
230230 const selectorType = getSelectorTypeOrThrow ( selector , 'find' )
231- if ( selectorType === selectorTypes . VUE_COMPONENT ) {
232- if ( ! selector . name ) {
233- throwError ( '.find() requires component to have a name property' )
234- }
231+
232+ if ( selectorType === selectorTypes . VUE_COMPONENT ||
233+ selectorType === selectorTypes . NAME_SELECTOR ) {
235234 const root = this . vm || this . vnode
236- const components = findVueComponents ( root , selector . name )
235+ // $FlowIgnore warning about selectorType being undefined
236+ const components = findVueComponents ( root , selectorType , selector )
237237 if ( components . length === 0 ) {
238238 return new ErrorWrapper ( 'Component' )
239239 }
240240 return new VueWrapper ( components [ 0 ] , this . options )
241241 }
242242
243- if ( selectorType === selectorTypes . OPTIONS_OBJECT ) {
243+ if ( selectorType === selectorTypes . REF_SELECTOR ) {
244244 if ( ! this . vm ) {
245245 throwError ( '$ref selectors can only be used on Vue component wrappers' )
246246 }
@@ -268,16 +268,15 @@ export default class Wrapper implements BaseWrapper {
268268 findAll ( selector : Selector ) : WrapperArray {
269269 const selectorType = getSelectorTypeOrThrow ( selector , 'findAll' )
270270
271- if ( selectorType === selectorTypes . VUE_COMPONENT ) {
272- if ( ! selector . name ) {
273- throwError ( '.findAll() requires component to have a name property' )
274- }
271+ if ( selectorType === selectorTypes . VUE_COMPONENT ||
272+ selectorType === selectorTypes . NAME_SELECTOR ) {
275273 const root = this . vm || this . vnode
276- const components = findVueComponents ( root , selector . name )
274+ // $FlowIgnore warning about selectorType being undefined
275+ const components = findVueComponents ( root , selectorType , selector )
277276 return new WrapperArray ( components . map ( component => new VueWrapper ( component , this . options ) ) )
278277 }
279278
280- if ( selectorType === selectorTypes . OPTIONS_OBJECT ) {
279+ if ( selectorType === selectorTypes . REF_SELECTOR ) {
281280 if ( ! this . vm ) {
282281 throwError ( '$ref selectors can only be used on Vue component wrappers' )
283282 }
@@ -311,14 +310,14 @@ export default class Wrapper implements BaseWrapper {
311310 is ( selector : Selector ) : boolean {
312311 const selectorType = getSelectorTypeOrThrow ( selector , 'is' )
313312
314- if ( selectorType === selectorTypes . VUE_COMPONENT && this . vm ) {
315- if ( typeof selector . name !== 'string' ) {
316- throwError ( 'a Component used as a selector must have a name property' )
313+ if ( selectorType === selectorTypes . NAME_SELECTOR ) {
314+ if ( ! this . vm ) {
315+ return false
317316 }
318317 return vmCtorMatchesName ( this . vm , selector . name )
319318 }
320319
321- if ( selectorType === selectorTypes . OPTIONS_OBJECT ) {
320+ if ( selectorType === selectorTypes . REF_SELECTOR ) {
322321 throwError ( '$ref selectors can not be used with wrapper.is()' )
323322 }
324323
0 commit comments