@@ -398,15 +398,18 @@ export default class Wrapper implements BaseWrapper {
398
398
if ( ! this . vm ) {
399
399
throwError ( 'wrapper.props() must be called on a Vue instance' )
400
400
}
401
- // $props object does not exist in Vue 2.1.x, so use $options.propsData instead
402
- let _props
403
- if ( this . vm && this . vm . $options && this . vm . $options . propsData ) {
404
- _props = this . vm . $options . propsData
405
- } else {
406
- // $FlowIgnore
407
- _props = this . vm . $props
401
+
402
+ const props = { }
403
+ // $FlowIgnore
404
+ const keys = this . vm . $options . _propKeys
405
+
406
+ if ( keys ) {
407
+ keys . forEach ( key => {
408
+ // $FlowIgnore
409
+ props [ key ] = this . vm [ key ]
410
+ } )
408
411
}
409
- return _props || { } // Return an empty object if no props exist
412
+ return props
410
413
}
411
414
412
415
/**
@@ -518,26 +521,21 @@ export default class Wrapper implements BaseWrapper {
518
521
if ( this . isFunctionalComponent ) {
519
522
throwError ( 'wrapper.setProps() cannot be called on a functional component' )
520
523
}
521
- if ( ! this . isVueInstance ( ) || ! this . vm ) {
524
+ if ( ! this . isVm ) {
522
525
throwError ( 'wrapper.setProps() can only be called on a Vue instance' )
523
526
}
524
- if ( this . vm && this . vm . $options && ! this . vm . $options . propsData ) {
525
- this . vm . $options . propsData = { }
526
- }
527
+
527
528
Object . keys ( data ) . forEach ( ( key ) => {
528
529
// Ignore properties that were not specified in the component options
529
530
// $FlowIgnore : Problem with possibly null this.vm
530
- if ( ! this . vm . $options . _propKeys || ! this . vm . $options . _propKeys . some ( prop => prop === key ) ) {
531
+ if ( ! this . vm . $options . _propKeys ||
532
+ ! this . vm . $options . _propKeys . some ( prop => prop === key ) ) {
531
533
throwError ( `wrapper.setProps() called with ${ key } property which is not defined on component` )
532
534
}
533
535
534
536
// $FlowIgnore : Problem with possibly null this.vm
535
537
if ( this . vm . _props ) {
536
538
this . vm . _props [ key ] = data [ key ]
537
- // $FlowIgnore : Problem with possibly null this.vm.$props
538
- this . vm . $props [ key ] = data [ key ]
539
- // $FlowIgnore : Problem with possibly null this.vm.$options
540
- this . vm . $options . propsData [ key ] = data [ key ]
541
539
} else {
542
540
// $FlowIgnore : Problem with possibly null this.vm
543
541
this . vm [ key ] = data [ key ]
0 commit comments