File tree 2 files changed +8
-1
lines changed
test/unit/specs/mount/Wrapper
2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -244,6 +244,9 @@ export default class Wrapper implements BaseWrapper {
244
244
if ( ! this . isVueComponent ) {
245
245
throwError ( '$ref selectors can only be used on Vue component wrappers' )
246
246
}
247
+ if ( this . vm && this . vm . $refs && selector . ref in this . vm . $refs && this . vm . $refs [ selector . ref ] instanceof Vue ) {
248
+ return new VueWrapper ( this . vm . $refs [ selector . ref ] , this . options )
249
+ }
247
250
const nodes = findVNodesByRef ( this . vnode , selector . ref )
248
251
if ( nodes . length === 0 ) {
249
252
return new ErrorWrapper ( `ref="${ selector . ref } "` )
@@ -278,6 +281,9 @@ export default class Wrapper implements BaseWrapper {
278
281
if ( ! this . isVueComponent ) {
279
282
throwError ( '$ref selectors can only be used on Vue component wrappers' )
280
283
}
284
+ if ( this . vm && this . vm . $refs && selector . ref in this . vm . $refs && this . vm . $refs [ selector . ref ] instanceof Vue ) {
285
+ return new WrapperArray ( [ new VueWrapper ( this . vm . $refs [ selector . ref ] , this . options ) ] )
286
+ }
281
287
const nodes = findVNodesByRef ( this . vnode , selector . ref )
282
288
return new WrapperArray ( nodes . map ( node => new Wrapper ( node , this . update , this . options ) ) )
283
289
}
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import ComponentWithoutName from '~resources/components/component-without-name.v
6
6
import ComponentWithSlots from '~resources/components/component-with-slots.vue'
7
7
import ComponentWithVFor from '~resources/components/component-with-v-for.vue'
8
8
import Component from '~resources/components/component.vue'
9
+ import VueWrapper from '~src/wrappers/vue-wrapper'
9
10
import Wrapper from '~src/wrappers/wrapper'
10
11
import ErrorWrapper from '~src/wrappers/error-wrapper'
11
12
@@ -172,7 +173,7 @@ describe('find', () => {
172
173
173
174
it ( 'returns Wrapper of Vue Components matching the ref in options object' , ( ) => {
174
175
const wrapper = mount ( ComponentWithChild )
175
- expect ( wrapper . find ( { ref : 'child' } ) ) . to . be . instanceOf ( Wrapper )
176
+ expect ( wrapper . find ( { ref : 'child' } ) ) . to . be . instanceOf ( VueWrapper )
176
177
} )
177
178
178
179
it ( 'throws an error when ref selector is called on a wrapper that is not a Vue component' , ( ) => {
You can’t perform that action at this time.
0 commit comments