@@ -2592,6 +2592,9 @@ function getCoreProperties (component) {
2592
2592
}
2593
2593
}
2594
2594
function createStubFromString ( templateString , originalComponent ) {
2595
+ if ( ! vueTemplateCompiler . compileToFunctions ) {
2596
+ throwError ( 'vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined' ) ;
2597
+ }
2595
2598
return Object . assign ( { } , getCoreProperties ( originalComponent ) ,
2596
2599
vueTemplateCompiler . compileToFunctions ( templateString ) )
2597
2600
}
@@ -2634,6 +2637,9 @@ function stubComponents (component, stubs) {
2634
2637
}
2635
2638
} else {
2636
2639
if ( typeof stubs [ stub ] === 'string' ) {
2640
+ if ( ! vueTemplateCompiler . compileToFunctions ) {
2641
+ throwError ( 'vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined' ) ;
2642
+ }
2637
2643
component . components [ stub ] = Object . assign ( { } , vueTemplateCompiler . compileToFunctions ( stubs [ stub ] ) ) ;
2638
2644
stubLifeCycleEvents ( component . components [ stub ] ) ;
2639
2645
} else {
@@ -3067,7 +3073,7 @@ Wrapper.prototype.hasAttribute = function hasAttribute (attribute, value) {
3067
3073
throwError ( 'wrapper.hasAttribute() must be passed value as a string' ) ;
3068
3074
}
3069
3075
3070
- return this . element && this . element . getAttribute ( attribute ) === value
3076
+ return ! ! ( this . element && this . element . getAttribute ( attribute ) === value )
3071
3077
} ;
3072
3078
3073
3079
/**
@@ -3078,7 +3084,7 @@ Wrapper.prototype.hasClass = function hasClass (className) {
3078
3084
throwError ( 'wrapper.hasClass() must be passed a string' ) ;
3079
3085
}
3080
3086
3081
- return this . element . className . split ( ' ' ) . indexOf ( className ) !== - 1
3087
+ return ! ! ( this . element && this . element . classList . contains ( className ) )
3082
3088
} ;
3083
3089
3084
3090
/**
@@ -3219,7 +3225,10 @@ Wrapper.prototype.is = function is (selector) {
3219
3225
}
3220
3226
return vmCtorMatchesName ( this . vm , selector . name )
3221
3227
}
3222
- return this . element . getAttribute && this . element . matches ( selector )
3228
+
3229
+ return ! ! ( this . element &&
3230
+ this . element . getAttribute &&
3231
+ this . element . matches ( selector ) )
3223
3232
} ;
3224
3233
3225
3234
/**
@@ -3317,6 +3326,10 @@ Wrapper.prototype.setProps = function setProps (data) {
3317
3326
* Return text of wrapper element
3318
3327
*/
3319
3328
Wrapper . prototype . text = function text ( ) {
3329
+ if ( ! this . element ) {
3330
+ throwError ( 'cannot call wrapper.text() on a wrapper without an element' ) ;
3331
+ }
3332
+
3320
3333
return this . element . textContent
3321
3334
} ;
3322
3335
@@ -3330,6 +3343,10 @@ Wrapper.prototype.trigger = function trigger (type, options) {
3330
3343
throwError ( 'wrapper.trigger() must be passed a string' ) ;
3331
3344
}
3332
3345
3346
+ if ( ! this . element ) {
3347
+ throwError ( 'cannot call wrapper.trigger() on a wrapper without an element' ) ;
3348
+ }
3349
+
3333
3350
var modifiers = {
3334
3351
enter : 13 ,
3335
3352
tab : 9 ,
@@ -3403,12 +3420,18 @@ function isValidSlot (slot) {
3403
3420
function addSlotToVm ( vm , slotName , slotValue ) {
3404
3421
if ( Array . isArray ( vm . $slots [ slotName ] ) ) {
3405
3422
if ( typeof slotValue === 'string' ) {
3423
+ if ( ! vueTemplateCompiler . compileToFunctions ) {
3424
+ throwError ( 'vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined' ) ;
3425
+ }
3406
3426
vm . $slots [ slotName ] . push ( vm . $createElement ( vueTemplateCompiler . compileToFunctions ( slotValue ) ) ) ;
3407
3427
} else {
3408
3428
vm . $slots [ slotName ] . push ( vm . $createElement ( slotValue ) ) ;
3409
3429
}
3410
3430
} else {
3411
3431
if ( typeof slotValue === 'string' ) {
3432
+ if ( ! vueTemplateCompiler . compileToFunctions ) {
3433
+ throwError ( 'vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined' ) ;
3434
+ }
3412
3435
vm . $slots [ slotName ] = [ vm . $createElement ( vueTemplateCompiler . compileToFunctions ( slotValue ) ) ] ;
3413
3436
} else {
3414
3437
vm . $slots [ slotName ] = [ vm . $createElement ( slotValue ) ] ; // eslint-disable-line no-param-reassign
@@ -3444,6 +3467,28 @@ function createInterceptPlugin (interceptedProperties) {
3444
3467
}
3445
3468
}
3446
3469
3470
+ function addAttrs ( vm , attrs ) {
3471
+ var consoleWarnSave = console . error ;
3472
+ console . error = function ( ) { } ;
3473
+ if ( attrs ) {
3474
+ vm . $attrs = attrs ;
3475
+ } else {
3476
+ vm . $attrs = { } ;
3477
+ }
3478
+ console . error = consoleWarnSave ;
3479
+ }
3480
+
3481
+ function addListeners ( vm , listeners ) {
3482
+ var consoleWarnSave = console . error ;
3483
+ console . error = function ( ) { } ;
3484
+ if ( listeners ) {
3485
+ vm . $listeners = listeners ;
3486
+ } else {
3487
+ vm . $listeners = { } ;
3488
+ }
3489
+ console . error = consoleWarnSave ;
3490
+ }
3491
+
3447
3492
function addProvide ( component , options ) {
3448
3493
var provide = typeof options . provide === 'function'
3449
3494
? options . provide
@@ -3498,6 +3543,9 @@ function createConstructor (component, options) {
3498
3543
3499
3544
var vm = new Constructor ( options ) ;
3500
3545
3546
+ addAttrs ( vm , options . attrs ) ;
3547
+ addListeners ( vm , options . listeners ) ;
3548
+
3501
3549
if ( options . slots ) {
3502
3550
addSlots ( vm , options . slots ) ;
3503
3551
}
@@ -3580,15 +3628,30 @@ function shallow (component, options) {
3580
3628
3581
3629
function createLocalVue ( ) {
3582
3630
var instance = Vue . extend ( ) ;
3583
- instance . version = Vue . version ;
3584
- instance . _installedPlugins = [ ] ;
3631
+
3632
+ // clone global APIs
3633
+ Object . keys ( Vue ) . forEach ( function ( key ) {
3634
+ if ( ! instance . hasOwnProperty ( key ) ) {
3635
+ var original = Vue [ key ] ;
3636
+ instance [ key ] = typeof original === 'object'
3637
+ ? cloneDeep_1 ( original )
3638
+ : original ;
3639
+ }
3640
+ } ) ;
3641
+
3642
+ // config is not enumerable
3585
3643
instance . config = cloneDeep_1 ( Vue . config ) ;
3586
- instance . util = cloneDeep_1 ( Vue . util ) ;
3587
- instance . _use = instance . use ;
3644
+
3645
+ // option merge strategies need to be exposed by reference
3646
+ // so that merge strats registered by plguins can work properly
3647
+ instance . config . optionMergeStrategies = Vue . config . optionMergeStrategies ;
3648
+
3649
+ // compat for vue-router < 2.7.1 where it does not allow multiple installs
3650
+ var use = instance . use ;
3588
3651
instance . use = function ( plugin ) {
3589
3652
plugin . installed = false ;
3590
3653
plugin . install . installed = false ;
3591
- instance . _use ( plugin ) ;
3654
+ use . call ( instance , plugin ) ;
3592
3655
} ;
3593
3656
return instance
3594
3657
}
0 commit comments