@@ -2802,26 +2802,42 @@ function getSelectorTypeOrThrow (selector, methodName) {
28022802
28032803//
28042804
2805- function findAllVueComponents ( vm , components ) {
2805+ function findAllVueComponentsFromVm ( vm , components ) {
28062806 if ( components === void 0 ) components = [ ] ;
28072807
28082808 components . push ( vm ) ;
2809-
28102809 vm . $children . forEach ( function ( child ) {
2811- findAllVueComponents ( child , components ) ;
2810+ findAllVueComponentsFromVm ( child , components ) ;
28122811 } ) ;
28132812
28142813 return components
28152814}
28162815
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+
28172832function vmCtorMatchesName ( vm , name ) {
28182833 return ( vm . $vnode && vm . $vnode . componentOptions && vm . $vnode . componentOptions . Ctor . options . name === name ) ||
28192834 ( vm . _vnode && vm . _vnode . functionalOptions && vm . _vnode . functionalOptions . name === name ) ||
28202835 vm . $options && vm . $options . name === name
28212836}
28222837
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 ) ;
28252841 return components . filter ( function ( component ) {
28262842 if ( ! component . $vnode ) {
28272843 return false
@@ -2920,8 +2936,9 @@ WrapperArray.prototype.contains = function contains (selector) {
29202936
29212937 return this . wrappers . every ( function ( wrapper ) { return wrapper . contains ( selector ) ; } )
29222938} ;
2939+
29232940WrapperArray . prototype . exists = function exists ( ) {
2924- return this . wrappers . length > 0
2941+ return this . length > 0 && this . wrappers . every ( function ( wrapper ) { return wrapper . exists ( ) ; } )
29252942} ;
29262943
29272944WrapperArray . prototype . emitted = function emitted ( ) {
@@ -3277,6 +3294,9 @@ Wrapper.prototype.emittedByOrder = function emittedByOrder () {
32773294 * Utility to check wrapper exists. Returns true as Wrapper always exists
32783295 */
32793296Wrapper . prototype . exists = function exists ( ) {
3297+ if ( this . isVueComponent ) {
3298+ return ! ! this . vm && ! this . vm . _isDestroyed
3299+ }
32803300 return true
32813301} ;
32823302
@@ -3379,13 +3399,12 @@ Wrapper.prototype.hasStyle = function hasStyle (style, value) {
33793399 */
33803400Wrapper . prototype . find = function find ( selector ) {
33813401 var selectorType = getSelectorTypeOrThrow ( selector , 'find' ) ;
3382-
33833402 if ( selectorType === selectorTypes . VUE_COMPONENT ) {
33843403 if ( ! selector . name ) {
33853404 throwError ( '.find() requires component to have a name property' ) ;
33863405 }
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 ) ;
33893408 if ( components . length === 0 ) {
33903409 return new ErrorWrapper ( 'Component' )
33913410 }
@@ -3423,8 +3442,8 @@ Wrapper.prototype.findAll = function findAll (selector) {
34233442 if ( ! selector . name ) {
34243443 throwError ( '.findAll() requires component to have a name property' ) ;
34253444 }
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 ) ;
34283447 return new WrapperArray ( components . map ( function ( component ) { return new VueWrapper ( component , this$1 . options ) ; } ) )
34293448 }
34303449
@@ -3577,6 +3596,10 @@ Wrapper.prototype.setComputed = function setComputed (computed) {
35773596 }
35783597 } ) ;
35793598 }
3599+ // $FlowIgnore
3600+ this$1 . vm . _watchers . forEach ( function ( watcher ) {
3601+ if ( watcher . expression === key ) { watcher . run ( ) ; }
3602+ } ) ;
35803603 } ) ;
35813604 this . update ( ) ;
35823605} ;
@@ -3679,46 +3702,50 @@ Wrapper.prototype.trigger = function trigger (type, options) {
36793702 up : 38 ,
36803703 down : 40 ,
36813704 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
36833712 } ;
36843713
36853714 var event = type . split ( '.' ) ;
36863715
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+ }
36913728
36923729 if ( options && options . preventDefault ) {
36933730 eventObject . preventDefault ( ) ;
36943731 }
36953732
36963733 if ( options ) {
36973734 Object . keys ( options ) . forEach ( function ( key ) {
3735+ // $FlowIgnore
36983736 eventObject [ key ] = options [ key ] ;
36993737 } ) ;
37003738 }
37013739
37023740 if ( event . length === 2 ) {
3741+ // $FlowIgnore
37033742 eventObject . keyCode = modifiers [ event [ 1 ] ] ;
37043743 }
37053744
37063745 this . element . dispatchEvent ( eventObject ) ;
37073746 this . update ( ) ;
37083747} ;
37093748
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-
37223749//
37233750
37243751function update ( ) {
@@ -3742,10 +3769,8 @@ var VueWrapper = (function (Wrapper$$1) {
37423769 } ) ) ;
37433770 this . vm = vm ;
37443771 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 ;
37493774 }
37503775
37513776 if ( Wrapper$$1 ) VueWrapper . __proto__ = Wrapper$$1 ;
@@ -3757,35 +3782,39 @@ var VueWrapper = (function (Wrapper$$1) {
37573782
37583783//
37593784
3760- function isValidSlot$1 ( slot ) {
3785+ function isValidSlot ( slot ) {
37613786 return Array . isArray ( slot ) || ( slot !== null && typeof slot === 'object' ) || typeof slot === 'string'
37623787}
37633788
37643789function 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' ) ;
37733795 }
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 ) ) ;
37803798 } 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 vue@2.2+' ) ;
3803+ }
37823804 }
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 ] ;
37833812 }
37843813}
37853814
37863815function addSlots ( vm , slots ) {
37873816 Object . keys ( slots ) . forEach ( function ( key ) {
3788- if ( ! isValidSlot$1 ( slots [ key ] ) ) {
3817+ if ( ! isValidSlot ( slots [ key ] ) ) {
37893818 throwError ( 'slots[key] must be a Component, string or an array of Components' ) ;
37903819 }
37913820
@@ -3843,6 +3872,30 @@ function addProvide (component, optionProvide, options) {
38433872
38443873//
38453874
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+
38463899function compileTemplate ( component ) {
38473900 Object . assign ( component , vueTemplateCompiler . compileToFunctions ( component . template ) ) ;
38483901}
@@ -4077,7 +4130,7 @@ function deleteMountingOptions (options) {
40774130
40784131//
40794132
4080- function isValidSlot ( slot ) {
4133+ function isValidSlot$1 ( slot ) {
40814134 return Array . isArray ( slot ) || ( slot !== null && typeof slot === 'object' ) || typeof slot === 'string'
40824135}
40834136
@@ -4095,7 +4148,7 @@ function createFunctionalSlots (slots, h) {
40954148 Object . keys ( slots ) . forEach ( function ( slotType ) {
40964149 if ( Array . isArray ( slots [ slotType ] ) ) {
40974150 slots [ slotType ] . forEach ( function ( slot ) {
4098- if ( ! isValidSlot ( slot ) ) {
4151+ if ( ! isValidSlot$1 ( slot ) ) {
40994152 throwError ( 'slots[key] must be a Component, string or an array of Components' ) ;
41004153 }
41014154 var component = typeof slot === 'string' ? vueTemplateCompiler . compileToFunctions ( slot ) : slot ;
@@ -4104,7 +4157,7 @@ function createFunctionalSlots (slots, h) {
41044157 children . push ( newSlot ) ;
41054158 } ) ;
41064159 } else {
4107- if ( ! isValidSlot ( slots [ slotType ] ) ) {
4160+ if ( ! isValidSlot$1 ( slots [ slotType ] ) ) {
41084161 throwError ( 'slots[key] must be a Component, string or an array of Components' ) ;
41094162 }
41104163 var component = typeof slots [ slotType ] === 'string' ? vueTemplateCompiler . compileToFunctions ( slots [ slotType ] ) : slots [ slotType ] ;
@@ -4116,6 +4169,25 @@ function createFunctionalSlots (slots, h) {
41164169 return children
41174170}
41184171
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+
41194191function createConstructor (
41204192 component ,
41214193 options
@@ -4129,20 +4201,7 @@ function createConstructor (
41294201 }
41304202
41314203 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 ) ;
41464205 } else if ( mountingOptions . context ) {
41474206 throwError (
41484207 'mount.context can only be used when mounting a functional component'
@@ -4161,6 +4220,8 @@ function createConstructor (
41614220 compileTemplate ( component ) ;
41624221 }
41634222
4223+ addEventLogger ( vue ) ;
4224+
41644225 var Constructor = vue . extend ( component ) ;
41654226
41664227 var instanceOptions = Object . assign ( { } , options ) ;
@@ -4206,6 +4267,32 @@ if (!Element.prototype.matches) {
42064267 } ;
42074268}
42084269
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+
42094296//
42104297
42114298Vue . config . productionTip = false ;
0 commit comments