@@ -2541,6 +2541,10 @@ function throwError (msg) {
2541
2541
throw new Error ( ( "[vue-test-utils]: " + msg ) )
2542
2542
}
2543
2543
2544
+ function warn ( msg ) {
2545
+ console . error ( ( "[vue-test-utils]: " + msg ) ) ;
2546
+ }
2547
+
2544
2548
//
2545
2549
2546
2550
var LIFECYCLE_HOOKS = [
@@ -2917,6 +2921,12 @@ WrapperArray.prototype.throwErrorIfWrappersIsEmpty = function throwErrorIfWrappe
2917
2921
}
2918
2922
} ;
2919
2923
2924
+ WrapperArray . prototype . setComputed = function setComputed ( computed ) {
2925
+ this . throwErrorIfWrappersIsEmpty ( 'setComputed' ) ;
2926
+
2927
+ this . wrappers . forEach ( function ( wrapper ) { return wrapper . setComputed ( computed ) ; } ) ;
2928
+ } ;
2929
+
2920
2930
WrapperArray . prototype . setData = function setData ( data ) {
2921
2931
this . throwErrorIfWrappersIsEmpty ( 'setData' ) ;
2922
2932
@@ -3020,6 +3030,10 @@ ErrorWrapper.prototype.text = function text () {
3020
3030
throwError ( ( "find did not return " + ( this . selector ) + ", cannot call text() on empty Wrapper" ) ) ;
3021
3031
} ;
3022
3032
3033
+ ErrorWrapper . prototype . setComputed = function setComputed ( ) {
3034
+ throwError ( ( "find did not return " + ( this . selector ) + ", cannot call setComputed() on empty Wrapper" ) ) ;
3035
+ } ;
3036
+
3023
3037
ErrorWrapper . prototype . setData = function setData ( ) {
3024
3038
throwError ( ( "find did not return " + ( this . selector ) + ", cannot call setData() on empty Wrapper" ) ) ;
3025
3039
} ;
@@ -3047,6 +3061,7 @@ var Wrapper = function Wrapper (vnode, update, options) {
3047
3061
this . element = vnode . elm ;
3048
3062
this . update = update ;
3049
3063
this . options = options ;
3064
+ this . version = Number ( ( ( Vue . version . split ( '.' ) [ 0 ] ) + "." + ( Vue . version . split ( '.' ) [ 1 ] ) ) ) ;
3050
3065
} ;
3051
3066
3052
3067
Wrapper . prototype . at = function at ( ) {
@@ -3242,9 +3257,7 @@ Wrapper.prototype.findAll = function findAll (selector) {
3242
3257
* Returns HTML of element as a string
3243
3258
*/
3244
3259
Wrapper . prototype . html = function html ( ) {
3245
- var tmp = document . createElement ( 'div' ) ;
3246
- tmp . appendChild ( this . element ) ;
3247
- return tmp . innerHTML
3260
+ return this . element . outerHTML
3248
3261
} ;
3249
3262
3250
3263
/**
@@ -3274,7 +3287,7 @@ Wrapper.prototype.is = function is (selector) {
3274
3287
* Checks if node is empty
3275
3288
*/
3276
3289
Wrapper . prototype . isEmpty = function isEmpty ( ) {
3277
- return this . vnode . children === undefined
3290
+ return this . vnode . children === undefined || this . vnode . children . length === 0
3278
3291
} ;
3279
3292
3280
3293
/**
@@ -3313,7 +3326,41 @@ Wrapper.prototype.setData = function setData (data) {
3313
3326
} ;
3314
3327
3315
3328
/**
3316
- * Sets vm data
3329
+ * Sets vm computed
3330
+ */
3331
+ Wrapper . prototype . setComputed = function setComputed ( computed ) {
3332
+ var this$1 = this ;
3333
+
3334
+ if ( ! this . isVueComponent ) {
3335
+ throwError ( 'wrapper.setComputed() can only be called on a Vue instance' ) ;
3336
+ }
3337
+
3338
+ Object . keys ( computed ) . forEach ( function ( key ) {
3339
+ if ( this$1 . version > 2.1 ) {
3340
+ // $FlowIgnore : Problem with possibly null this.vm
3341
+ if ( ! this$1 . vm . _computedWatchers [ key ] ) {
3342
+ throwError ( ( "wrapper.setComputed() was passed a value that does not exist as a computed property on the Vue instance. Property " + key + " does not exist on the Vue instance" ) ) ;
3343
+ }
3344
+ // $FlowIgnore : Problem with possibly null this.vm
3345
+ this$1 . vm . _computedWatchers [ key ] . value = computed [ key ] ;
3346
+ } else {
3347
+ // $FlowIgnore : Problem with possibly null this.vm
3348
+ if ( ! this$1 . vm . _watchers . some ( function ( w ) { return w . getter . name === key ; } ) ) {
3349
+ throwError ( ( "wrapper.setComputed() was passed a value that does not exist as a computed property on the Vue instance. Property " + key + " does not exist on the Vue instance" ) ) ;
3350
+ }
3351
+ // $FlowIgnore : Problem with possibly null this.vm
3352
+ this$1 . vm . _watchers . forEach ( function ( watcher ) {
3353
+ if ( watcher . getter . name === key ) {
3354
+ watcher . value = computed [ key ] ;
3355
+ }
3356
+ } ) ;
3357
+ }
3358
+ } ) ;
3359
+ this . update ( ) ;
3360
+ } ;
3361
+
3362
+ /**
3363
+ * Sets vm methods
3317
3364
*/
3318
3365
Wrapper . prototype . setMethods = function setMethods ( methods ) {
3319
3366
var this$1 = this ;
@@ -3439,6 +3486,7 @@ function logEvents (vm, emitted, emittedByOrder) {
3439
3486
3440
3487
function update ( ) {
3441
3488
this . _update ( this . _render ( ) ) ;
3489
+ this . $children . forEach ( function ( child ) { return update . call ( child ) ; } ) ;
3442
3490
}
3443
3491
3444
3492
var VueWrapper = ( function ( Wrapper$$1 ) {
@@ -3450,7 +3498,11 @@ var VueWrapper = (function (Wrapper$$1) {
3450
3498
get : function ( ) { return vm . _vnode ; } ,
3451
3499
set : function ( ) { }
3452
3500
} ) ) ;
3453
-
3501
+ // $FlowIgnore
3502
+ Object . defineProperty ( this , 'element' , ( {
3503
+ get : function ( ) { return vm . $el ; } ,
3504
+ set : function ( ) { }
3505
+ } ) ) ;
3454
3506
this . vm = vm ;
3455
3507
this . isVueComponent = true ;
3456
3508
this . _emitted = Object . create ( null ) ;
@@ -3519,23 +3571,25 @@ function addMocks (mockedProperties, Vue$$1) {
3519
3571
}
3520
3572
3521
3573
function addAttrs ( vm , attrs ) {
3574
+ var originalVueConfig = Vue . config ;
3522
3575
Vue . config . silent = true ;
3523
3576
if ( attrs ) {
3524
3577
vm . $attrs = attrs ;
3525
3578
} else {
3526
3579
vm . $attrs = { } ;
3527
3580
}
3528
- Vue . config . silent = false ;
3581
+ Vue . config . silent = originalVueConfig . silent ;
3529
3582
}
3530
3583
3531
3584
function addListeners ( vm , listeners ) {
3585
+ var originalVueConfig = Vue . config ;
3532
3586
Vue . config . silent = true ;
3533
3587
if ( listeners ) {
3534
3588
vm . $listeners = listeners ;
3535
3589
} else {
3536
3590
vm . $listeners = { } ;
3537
3591
}
3538
- Vue . config . silent = false ;
3592
+ Vue . config . silent = originalVueConfig . silent ;
3539
3593
}
3540
3594
3541
3595
function addProvide ( component , options ) {
@@ -3648,7 +3702,7 @@ function mount (component, options) {
3648
3702
throwError (
3649
3703
'window is undefined, vue-test-utils needs to be run in a browser environment.\n' +
3650
3704
'You can run the tests in node using jsdom + jsdom-global.\n' +
3651
- 'See https://vue-test-utils.vuejs.org/en/guides/general -tips.html for more details.'
3705
+ 'See https://vue-test-utils.vuejs.org/en/guides/common -tips.html for more details.'
3652
3706
) ;
3653
3707
}
3654
3708
@@ -3721,10 +3775,137 @@ function createLocalVue () {
3721
3775
return instance
3722
3776
}
3723
3777
3778
+ //
3779
+
3780
+ function getRealChild ( vnode ) {
3781
+ var compOptions = vnode && vnode . componentOptions ;
3782
+ if ( compOptions && compOptions . Ctor . options . abstract ) {
3783
+ return getRealChild ( getFirstComponentChild ( compOptions . children ) )
3784
+ } else {
3785
+ return vnode
3786
+ }
3787
+ }
3788
+
3789
+ function getFirstComponentChild ( children ) {
3790
+ if ( Array . isArray ( children ) ) {
3791
+ for ( var i = 0 ; i < children . length ; i ++ ) {
3792
+ var c = children [ i ] ;
3793
+ if ( c && ( c . componentOptions || isAsyncPlaceholder ( c ) ) ) {
3794
+ return c
3795
+ }
3796
+ }
3797
+ }
3798
+ }
3799
+
3800
+ function isAsyncPlaceholder ( node ) {
3801
+ return node . isComment && node . asyncFactory
3802
+ }
3803
+ var camelizeRE = / - ( \w ) / g;
3804
+ var camelize = function ( str ) {
3805
+ return str . replace ( camelizeRE , function ( _ , c ) { return c ? c . toUpperCase ( ) : '' ; } )
3806
+ } ;
3807
+
3808
+ function extractTransitionData ( comp ) {
3809
+ var data = { } ;
3810
+ var options = comp . $options ;
3811
+ // props
3812
+ for ( var key in options . propsData ) {
3813
+ data [ key ] = comp [ key ] ;
3814
+ }
3815
+ // events.
3816
+ // extract listeners and pass them directly to the transition methods
3817
+ var listeners = options . _parentListeners ;
3818
+ for ( var key$1 in listeners ) {
3819
+ data [ camelize ( key$1 ) ] = listeners [ key$1 ] ;
3820
+ }
3821
+ return data
3822
+ }
3823
+
3824
+ function hasParentTransition ( vnode ) {
3825
+ while ( ( vnode = vnode . parent ) ) {
3826
+ if ( vnode . data . transition ) {
3827
+ return true
3828
+ }
3829
+ }
3830
+ }
3831
+
3832
+ var TransitionStub = {
3833
+ render : function render ( h ) {
3834
+ var children = this . $options . _renderChildren ;
3835
+ if ( ! children ) {
3836
+ return
3837
+ }
3838
+
3839
+ // filter out text nodes (possible whitespaces)
3840
+ children = children . filter ( function ( c ) { return c . tag || isAsyncPlaceholder ( c ) ; } ) ;
3841
+ /* istanbul ignore if */
3842
+ if ( ! children . length ) {
3843
+ return
3844
+ }
3845
+
3846
+ // warn multiple elements
3847
+ if ( children . length > 1 ) {
3848
+ warn (
3849
+ '<transition> can only be used on a single element. Use ' +
3850
+ '<transition-group> for lists.'
3851
+ ) ;
3852
+ }
3853
+
3854
+ var mode = this . mode ;
3855
+
3856
+ // warn invalid mode
3857
+ if ( mode && mode !== 'in-out' && mode !== 'out-in'
3858
+ ) {
3859
+ warn (
3860
+ 'invalid <transition> mode: ' + mode
3861
+ ) ;
3862
+ }
3863
+
3864
+ var rawChild = children [ 0 ] ;
3865
+
3866
+ // if this is a component root node and the component's
3867
+ // parent container node also has transition, skip.
3868
+ if ( hasParentTransition ( this . $vnode ) ) {
3869
+ return rawChild
3870
+ }
3871
+
3872
+ // apply transition data to child
3873
+ // use getRealChild() to ignore abstract components e.g. keep-alive
3874
+ var child = getRealChild ( rawChild ) ;
3875
+
3876
+ if ( ! child ) {
3877
+ return rawChild
3878
+ }
3879
+
3880
+ ( child . data || ( child . data = { } ) ) . transition = extractTransitionData ( this ) ;
3881
+
3882
+ // mark v-show
3883
+ // so that the transition module can hand over the control to the directive
3884
+ if ( child . data . directives && child . data . directives . some ( function ( d ) { return d . name === 'show' ; } ) ) {
3885
+ child . data . show = true ;
3886
+ }
3887
+
3888
+ return rawChild
3889
+ }
3890
+ } ;
3891
+
3892
+ //
3893
+
3894
+ var TransitionGroupStub = {
3895
+ render : function render ( h ) {
3896
+ var tag = this . tag || this . $vnode . data . tag || 'span' ;
3897
+ var children = this . $slots . default || [ ] ;
3898
+
3899
+ return h ( tag , null , children )
3900
+ }
3901
+ } ;
3902
+
3724
3903
var index = {
3725
3904
createLocalVue : createLocalVue ,
3726
3905
mount : mount ,
3727
- shallow : shallow
3906
+ shallow : shallow ,
3907
+ TransitionStub : TransitionStub ,
3908
+ TransitionGroupStub : TransitionGroupStub
3728
3909
} ;
3729
3910
3730
3911
return index ;
0 commit comments