@@ -2802,26 +2802,42 @@ function getSelectorTypeOrThrow (selector, methodName) {
2802
2802
2803
2803
//
2804
2804
2805
- function findAllVueComponents ( vm , components ) {
2805
+ function findAllVueComponentsFromVm ( vm , components ) {
2806
2806
if ( components === void 0 ) components = [ ] ;
2807
2807
2808
2808
components . push ( vm ) ;
2809
-
2810
2809
vm . $children . forEach ( function ( child ) {
2811
- findAllVueComponents ( child , components ) ;
2810
+ findAllVueComponentsFromVm ( child , components ) ;
2812
2811
} ) ;
2813
2812
2814
2813
return components
2815
2814
}
2816
2815
2816
+ function findAllVueComponentsFromVnode ( vnode , components ) {
2817
+ if ( components === void 0 ) components = [ ] ;
2818
+
2819
+ debugger
2820
+ if ( vnode . child ) {
2821
+ components . push ( vnode . child ) ;
2822
+ }
2823
+ if ( vnode . children ) {
2824
+ vnode . children . forEach ( function ( child ) {
2825
+ findAllVueComponentsFromVnode ( child , components ) ;
2826
+ } ) ;
2827
+ }
2828
+
2829
+ return components
2830
+ }
2831
+
2817
2832
function vmCtorMatchesName ( vm , name ) {
2818
2833
return ( vm . $vnode && vm . $vnode . componentOptions && vm . $vnode . componentOptions . Ctor . options . name === name ) ||
2819
2834
( vm . _vnode && vm . _vnode . functionalOptions && vm . _vnode . functionalOptions . name === name ) ||
2820
2835
vm . $options && vm . $options . name === name
2821
2836
}
2822
2837
2823
- function findVueComponents ( vm , componentName ) {
2824
- var components = findAllVueComponents ( vm ) ;
2838
+ function findVueComponents ( root , componentName ) {
2839
+ debugger
2840
+ var components = root . _isVue ? findAllVueComponentsFromVm ( root ) : findAllVueComponentsFromVnode ( root ) ;
2825
2841
return components . filter ( function ( component ) {
2826
2842
if ( ! component . $vnode ) {
2827
2843
return false
@@ -2920,8 +2936,9 @@ WrapperArray.prototype.contains = function contains (selector) {
2920
2936
2921
2937
return this . wrappers . every ( function ( wrapper ) { return wrapper . contains ( selector ) ; } )
2922
2938
} ;
2939
+
2923
2940
WrapperArray . prototype . exists = function exists ( ) {
2924
- return this . wrappers . length > 0
2941
+ return this . length > 0 && this . wrappers . every ( function ( wrapper ) { return wrapper . exists ( ) ; } )
2925
2942
} ;
2926
2943
2927
2944
WrapperArray . prototype . emitted = function emitted ( ) {
@@ -3277,6 +3294,9 @@ Wrapper.prototype.emittedByOrder = function emittedByOrder () {
3277
3294
* Utility to check wrapper exists. Returns true as Wrapper always exists
3278
3295
*/
3279
3296
Wrapper . prototype . exists = function exists ( ) {
3297
+ if ( this . isVueComponent ) {
3298
+ return ! ! this . vm && ! this . vm . _isDestroyed
3299
+ }
3280
3300
return true
3281
3301
} ;
3282
3302
@@ -3379,13 +3399,12 @@ Wrapper.prototype.hasStyle = function hasStyle (style, value) {
3379
3399
*/
3380
3400
Wrapper . prototype . find = function find ( selector ) {
3381
3401
var selectorType = getSelectorTypeOrThrow ( selector , 'find' ) ;
3382
-
3383
3402
if ( selectorType === selectorTypes . VUE_COMPONENT ) {
3384
3403
if ( ! selector . name ) {
3385
3404
throwError ( '.find() requires component to have a name property' ) ;
3386
3405
}
3387
- var vm = this . vm || this . vnode . context . $root ;
3388
- var components = findVueComponents ( vm , selector . name ) ;
3406
+ var root = this . vm || this . vnode ;
3407
+ var components = findVueComponents ( root , selector . name ) ;
3389
3408
if ( components . length === 0 ) {
3390
3409
return new ErrorWrapper ( 'Component' )
3391
3410
}
@@ -3423,8 +3442,8 @@ Wrapper.prototype.findAll = function findAll (selector) {
3423
3442
if ( ! selector . name ) {
3424
3443
throwError ( '.findAll() requires component to have a name property' ) ;
3425
3444
}
3426
- var vm = this . vm || this . vnode . context . $root ;
3427
- var components = findVueComponents ( vm , selector . name ) ;
3445
+ var root = this . vm || this . vnode ;
3446
+ var components = findVueComponents ( root , selector . name ) ;
3428
3447
return new WrapperArray ( components . map ( function ( component ) { return new VueWrapper ( component , this$1 . options ) ; } ) )
3429
3448
}
3430
3449
@@ -3577,6 +3596,10 @@ Wrapper.prototype.setComputed = function setComputed (computed) {
3577
3596
}
3578
3597
} ) ;
3579
3598
}
3599
+ // $FlowIgnore
3600
+ this$1 . vm . _watchers . forEach ( function ( watcher ) {
3601
+ if ( watcher . expression === key ) { watcher . run ( ) ; }
3602
+ } ) ;
3580
3603
} ) ;
3581
3604
this . update ( ) ;
3582
3605
} ;
@@ -3679,46 +3702,50 @@ Wrapper.prototype.trigger = function trigger (type, options) {
3679
3702
up : 38 ,
3680
3703
down : 40 ,
3681
3704
left : 37 ,
3682
- right : 39
3705
+ right : 39 ,
3706
+ end : 35 ,
3707
+ home : 36 ,
3708
+ backspace : 8 ,
3709
+ insert : 45 ,
3710
+ pageup : 33 ,
3711
+ pagedown : 34
3683
3712
} ;
3684
3713
3685
3714
var event = type . split ( '.' ) ;
3686
3715
3687
- var eventObject = new window . Event ( event [ 0 ] , {
3688
- bubbles : true ,
3689
- cancelable : true
3690
- } ) ;
3716
+ var eventObject ;
3717
+
3718
+ // Fallback for IE10,11 - https://stackoverflow.com/questions/26596123
3719
+ if ( typeof ( window . Event ) === 'function' ) {
3720
+ eventObject = new window . Event ( event [ 0 ] , {
3721
+ bubbles : true ,
3722
+ cancelable : true
3723
+ } ) ;
3724
+ } else {
3725
+ eventObject = document . createEvent ( 'Event' ) ;
3726
+ eventObject . initEvent ( event [ 0 ] , true , true ) ;
3727
+ }
3691
3728
3692
3729
if ( options && options . preventDefault ) {
3693
3730
eventObject . preventDefault ( ) ;
3694
3731
}
3695
3732
3696
3733
if ( options ) {
3697
3734
Object . keys ( options ) . forEach ( function ( key ) {
3735
+ // $FlowIgnore
3698
3736
eventObject [ key ] = options [ key ] ;
3699
3737
} ) ;
3700
3738
}
3701
3739
3702
3740
if ( event . length === 2 ) {
3741
+ // $FlowIgnore
3703
3742
eventObject . keyCode = modifiers [ event [ 1 ] ] ;
3704
3743
}
3705
3744
3706
3745
this . element . dispatchEvent ( eventObject ) ;
3707
3746
this . update ( ) ;
3708
3747
} ;
3709
3748
3710
- function logEvents ( vm , emitted , emittedByOrder ) {
3711
- var emit = vm . $emit ;
3712
- vm . $emit = function ( name ) {
3713
- var args = [ ] , len = arguments . length - 1 ;
3714
- while ( len -- > 0 ) args [ len ] = arguments [ len + 1 ] ;
3715
-
3716
- ( emitted [ name ] || ( emitted [ name ] = [ ] ) ) . push ( args ) ;
3717
- emittedByOrder . push ( { name : name , args : args } ) ;
3718
- return emit . call . apply ( emit , [ vm , name ] . concat ( args ) )
3719
- } ;
3720
- }
3721
-
3722
3749
//
3723
3750
3724
3751
function update ( ) {
@@ -3742,10 +3769,8 @@ var VueWrapper = (function (Wrapper$$1) {
3742
3769
} ) ) ;
3743
3770
this . vm = vm ;
3744
3771
this . isVueComponent = true ;
3745
- this . _emitted = Object . create ( null ) ;
3746
- this . _emittedByOrder = [ ] ;
3747
-
3748
- logEvents ( vm , this . _emitted , this . _emittedByOrder ) ;
3772
+ this . _emitted = vm . __emitted ;
3773
+ this . _emittedByOrder = vm . __emittedByOrder ;
3749
3774
}
3750
3775
3751
3776
if ( Wrapper$$1 ) VueWrapper . __proto__ = Wrapper$$1 ;
@@ -3757,35 +3782,39 @@ var VueWrapper = (function (Wrapper$$1) {
3757
3782
3758
3783
//
3759
3784
3760
- function isValidSlot$1 ( slot ) {
3785
+ function isValidSlot ( slot ) {
3761
3786
return Array . isArray ( slot ) || ( slot !== null && typeof slot === 'object' ) || typeof slot === 'string'
3762
3787
}
3763
3788
3764
3789
function addSlotToVm ( vm , slotName , slotValue ) {
3765
- if ( Array . isArray ( vm . $slots [ slotName ] ) ) {
3766
- if ( typeof slotValue === 'string' ) {
3767
- if ( ! vueTemplateCompiler . compileToFunctions ) {
3768
- throwError ( 'vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined' ) ;
3769
- }
3770
- vm . $slots [ slotName ] . push ( vm . $createElement ( vueTemplateCompiler . compileToFunctions ( slotValue ) ) ) ;
3771
- } else {
3772
- vm . $slots [ slotName ] . push ( vm . $createElement ( slotValue ) ) ;
3790
+ var elem ;
3791
+ var vueVersion = Number ( ( ( Vue . version . split ( '.' ) [ 0 ] ) + "." + ( Vue . version . split ( '.' ) [ 1 ] ) ) ) ;
3792
+ if ( typeof slotValue === 'string' ) {
3793
+ if ( ! vueTemplateCompiler . compileToFunctions ) {
3794
+ throwError ( 'vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined' ) ;
3773
3795
}
3774
- } else {
3775
- if ( typeof slotValue === 'string' ) {
3776
- if ( ! vueTemplateCompiler . compileToFunctions ) {
3777
- throwError ( 'vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined' ) ;
3778
- }
3779
- vm . $slots [ slotName ] = [ vm . $createElement ( vueTemplateCompiler . compileToFunctions ( slotValue ) ) ] ;
3796
+ if ( slotValue . trim ( ) [ 0 ] === '<' ) {
3797
+ elem = vm . $createElement ( vueTemplateCompiler . compileToFunctions ( slotValue ) ) ;
3780
3798
} else {
3781
- vm . $slots [ slotName ] = [ vm . $createElement ( slotValue ) ] ; // eslint-disable-line no-param-reassign
3799
+ if ( vueVersion >= 2.2 ) {
3800
+ elem = vm . _v ( slotValue ) ;
3801
+ } else {
3802
+ throwError ( 'vue-test-utils support for passing text to slots at [email protected] +' ) ;
3803
+ }
3782
3804
}
3805
+ } else {
3806
+ elem = vm . $createElement ( slotValue ) ;
3807
+ }
3808
+ if ( Array . isArray ( vm . $slots [ slotName ] ) ) {
3809
+ vm . $slots [ slotName ] . push ( elem ) ;
3810
+ } else {
3811
+ vm . $slots [ slotName ] = [ elem ] ;
3783
3812
}
3784
3813
}
3785
3814
3786
3815
function addSlots ( vm , slots ) {
3787
3816
Object . keys ( slots ) . forEach ( function ( key ) {
3788
- if ( ! isValidSlot$1 ( slots [ key ] ) ) {
3817
+ if ( ! isValidSlot ( slots [ key ] ) ) {
3789
3818
throwError ( 'slots[key] must be a Component, string or an array of Components' ) ;
3790
3819
}
3791
3820
@@ -3843,6 +3872,30 @@ function addProvide (component, optionProvide, options) {
3843
3872
3844
3873
//
3845
3874
3875
+ function logEvents ( vm , emitted , emittedByOrder ) {
3876
+ var emit = vm . $emit ;
3877
+ vm . $emit = function ( name ) {
3878
+ var args = [ ] , len = arguments . length - 1 ;
3879
+ while ( len -- > 0 ) args [ len ] = arguments [ len + 1 ] ;
3880
+
3881
+ ( emitted [ name ] || ( emitted [ name ] = [ ] ) ) . push ( args ) ;
3882
+ emittedByOrder . push ( { name : name , args : args } ) ;
3883
+ return emit . call . apply ( emit , [ vm , name ] . concat ( args ) )
3884
+ } ;
3885
+ }
3886
+
3887
+ function addEventLogger ( vue ) {
3888
+ vue . mixin ( {
3889
+ beforeCreate : function ( ) {
3890
+ this . __emitted = Object . create ( null ) ;
3891
+ this . __emittedByOrder = [ ] ;
3892
+ logEvents ( this , this . __emitted , this . __emittedByOrder ) ;
3893
+ }
3894
+ } ) ;
3895
+ }
3896
+
3897
+ //
3898
+
3846
3899
function compileTemplate ( component ) {
3847
3900
Object . assign ( component , vueTemplateCompiler . compileToFunctions ( component . template ) ) ;
3848
3901
}
@@ -4077,7 +4130,7 @@ function deleteMountingOptions (options) {
4077
4130
4078
4131
//
4079
4132
4080
- function isValidSlot ( slot ) {
4133
+ function isValidSlot$1 ( slot ) {
4081
4134
return Array . isArray ( slot ) || ( slot !== null && typeof slot === 'object' ) || typeof slot === 'string'
4082
4135
}
4083
4136
@@ -4095,7 +4148,7 @@ function createFunctionalSlots (slots, h) {
4095
4148
Object . keys ( slots ) . forEach ( function ( slotType ) {
4096
4149
if ( Array . isArray ( slots [ slotType ] ) ) {
4097
4150
slots [ slotType ] . forEach ( function ( slot ) {
4098
- if ( ! isValidSlot ( slot ) ) {
4151
+ if ( ! isValidSlot$1 ( slot ) ) {
4099
4152
throwError ( 'slots[key] must be a Component, string or an array of Components' ) ;
4100
4153
}
4101
4154
var component = typeof slot === 'string' ? vueTemplateCompiler . compileToFunctions ( slot ) : slot ;
@@ -4104,7 +4157,7 @@ function createFunctionalSlots (slots, h) {
4104
4157
children . push ( newSlot ) ;
4105
4158
} ) ;
4106
4159
} else {
4107
- if ( ! isValidSlot ( slots [ slotType ] ) ) {
4160
+ if ( ! isValidSlot$1 ( slots [ slotType ] ) ) {
4108
4161
throwError ( 'slots[key] must be a Component, string or an array of Components' ) ;
4109
4162
}
4110
4163
var component = typeof slots [ slotType ] === 'string' ? vueTemplateCompiler . compileToFunctions ( slots [ slotType ] ) : slots [ slotType ] ;
@@ -4116,6 +4169,25 @@ function createFunctionalSlots (slots, h) {
4116
4169
return children
4117
4170
}
4118
4171
4172
+ function createFunctionalComponent ( component , mountingOptions ) {
4173
+ if ( mountingOptions . context && typeof mountingOptions . context !== 'object' ) {
4174
+ throwError ( 'mount.context must be an object' ) ;
4175
+ }
4176
+
4177
+ var clonedComponent = cloneDeep_1 ( component ) ;
4178
+ return {
4179
+ render : function render ( h ) {
4180
+ return h (
4181
+ clonedComponent ,
4182
+ mountingOptions . context || component . FunctionalRenderContext ,
4183
+ ( mountingOptions . context && mountingOptions . context . children && mountingOptions . context . children . map ( function ( x ) { return typeof x === 'function' ? x ( h ) : x ; } ) ) || createFunctionalSlots ( mountingOptions . slots , h )
4184
+ )
4185
+ }
4186
+ }
4187
+ }
4188
+
4189
+ //
4190
+
4119
4191
function createConstructor (
4120
4192
component ,
4121
4193
options
@@ -4129,20 +4201,7 @@ function createConstructor (
4129
4201
}
4130
4202
4131
4203
if ( component . functional ) {
4132
- if ( mountingOptions . context && typeof mountingOptions . context !== 'object' ) {
4133
- throwError ( 'mount.context must be an object' ) ;
4134
- }
4135
-
4136
- var clonedComponent = cloneDeep_1 ( component ) ;
4137
- component = {
4138
- render : function render ( h ) {
4139
- return h (
4140
- clonedComponent ,
4141
- mountingOptions . context || component . FunctionalRenderContext ,
4142
- ( mountingOptions . context && mountingOptions . context . children ) || createFunctionalSlots ( mountingOptions . slots , h )
4143
- )
4144
- }
4145
- } ;
4204
+ component = createFunctionalComponent ( component , mountingOptions ) ;
4146
4205
} else if ( mountingOptions . context ) {
4147
4206
throwError (
4148
4207
'mount.context can only be used when mounting a functional component'
@@ -4161,6 +4220,8 @@ function createConstructor (
4161
4220
compileTemplate ( component ) ;
4162
4221
}
4163
4222
4223
+ addEventLogger ( vue ) ;
4224
+
4164
4225
var Constructor = vue . extend ( component ) ;
4165
4226
4166
4227
var instanceOptions = Object . assign ( { } , options ) ;
@@ -4206,6 +4267,32 @@ if (!Element.prototype.matches) {
4206
4267
} ;
4207
4268
}
4208
4269
4270
+ if ( typeof Object . assign !== 'function' ) {
4271
+ ( function ( ) {
4272
+ Object . assign = function ( target ) {
4273
+ 'use strict' ;
4274
+ var arguments$1 = arguments ;
4275
+
4276
+ if ( target === undefined || target === null ) {
4277
+ throw new TypeError ( 'Cannot convert undefined or null to object' )
4278
+ }
4279
+
4280
+ var output = Object ( target ) ;
4281
+ for ( var index = 1 ; index < arguments . length ; index ++ ) {
4282
+ var source = arguments$1 [ index ] ;
4283
+ if ( source !== undefined && source !== null ) {
4284
+ for ( var nextKey in source ) {
4285
+ if ( source . hasOwnProperty ( nextKey ) ) {
4286
+ output [ nextKey ] = source [ nextKey ] ;
4287
+ }
4288
+ }
4289
+ }
4290
+ }
4291
+ return output
4292
+ } ;
4293
+ } ) ( ) ;
4294
+ }
4295
+
4209
4296
//
4210
4297
4211
4298
Vue . config . productionTip = false ;
0 commit comments