@@ -2592,6 +2592,9 @@ function getCoreProperties (component) {
25922592 }
25932593}
25942594function createStubFromString ( templateString , originalComponent ) {
2595+ if ( ! vueTemplateCompiler . compileToFunctions ) {
2596+ throwError ( 'vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined' ) ;
2597+ }
25952598 return Object . assign ( { } , getCoreProperties ( originalComponent ) ,
25962599 vueTemplateCompiler . compileToFunctions ( templateString ) )
25972600}
@@ -2634,6 +2637,9 @@ function stubComponents (component, stubs) {
26342637 }
26352638 } else {
26362639 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+ }
26372643 component . components [ stub ] = Object . assign ( { } , vueTemplateCompiler . compileToFunctions ( stubs [ stub ] ) ) ;
26382644 stubLifeCycleEvents ( component . components [ stub ] ) ;
26392645 } else {
@@ -3067,7 +3073,7 @@ Wrapper.prototype.hasAttribute = function hasAttribute (attribute, value) {
30673073 throwError ( 'wrapper.hasAttribute() must be passed value as a string' ) ;
30683074 }
30693075
3070- return this . element && this . element . getAttribute ( attribute ) === value
3076+ return ! ! ( this . element && this . element . getAttribute ( attribute ) === value )
30713077} ;
30723078
30733079/**
@@ -3078,7 +3084,7 @@ Wrapper.prototype.hasClass = function hasClass (className) {
30783084 throwError ( 'wrapper.hasClass() must be passed a string' ) ;
30793085 }
30803086
3081- return this . element . className . split ( ' ' ) . indexOf ( className ) !== - 1
3087+ return ! ! ( this . element && this . element . classList . contains ( className ) )
30823088} ;
30833089
30843090/**
@@ -3219,7 +3225,10 @@ Wrapper.prototype.is = function is (selector) {
32193225 }
32203226 return vmCtorMatchesName ( this . vm , selector . name )
32213227 }
3222- return this . element . getAttribute && this . element . matches ( selector )
3228+
3229+ return ! ! ( this . element &&
3230+ this . element . getAttribute &&
3231+ this . element . matches ( selector ) )
32233232} ;
32243233
32253234/**
@@ -3317,6 +3326,10 @@ Wrapper.prototype.setProps = function setProps (data) {
33173326 * Return text of wrapper element
33183327 */
33193328Wrapper . prototype . text = function text ( ) {
3329+ if ( ! this . element ) {
3330+ throwError ( 'cannot call wrapper.text() on a wrapper without an element' ) ;
3331+ }
3332+
33203333 return this . element . textContent
33213334} ;
33223335
@@ -3330,6 +3343,10 @@ Wrapper.prototype.trigger = function trigger (type, options) {
33303343 throwError ( 'wrapper.trigger() must be passed a string' ) ;
33313344 }
33323345
3346+ if ( ! this . element ) {
3347+ throwError ( 'cannot call wrapper.trigger() on a wrapper without an element' ) ;
3348+ }
3349+
33333350 var modifiers = {
33343351 enter : 13 ,
33353352 tab : 9 ,
@@ -3403,12 +3420,18 @@ function isValidSlot (slot) {
34033420function addSlotToVm ( vm , slotName , slotValue ) {
34043421 if ( Array . isArray ( vm . $slots [ slotName ] ) ) {
34053422 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+ }
34063426 vm . $slots [ slotName ] . push ( vm . $createElement ( vueTemplateCompiler . compileToFunctions ( slotValue ) ) ) ;
34073427 } else {
34083428 vm . $slots [ slotName ] . push ( vm . $createElement ( slotValue ) ) ;
34093429 }
34103430 } else {
34113431 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+ }
34123435 vm . $slots [ slotName ] = [ vm . $createElement ( vueTemplateCompiler . compileToFunctions ( slotValue ) ) ] ;
34133436 } else {
34143437 vm . $slots [ slotName ] = [ vm . $createElement ( slotValue ) ] ; // eslint-disable-line no-param-reassign
@@ -3444,6 +3467,28 @@ function createInterceptPlugin (interceptedProperties) {
34443467 }
34453468}
34463469
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+
34473492function addProvide ( component , options ) {
34483493 var provide = typeof options . provide === 'function'
34493494 ? options . provide
@@ -3498,6 +3543,9 @@ function createConstructor (component, options) {
34983543
34993544 var vm = new Constructor ( options ) ;
35003545
3546+ addAttrs ( vm , options . attrs ) ;
3547+ addListeners ( vm , options . listeners ) ;
3548+
35013549 if ( options . slots ) {
35023550 addSlots ( vm , options . slots ) ;
35033551 }
@@ -3580,15 +3628,30 @@ function shallow (component, options) {
35803628
35813629function createLocalVue ( ) {
35823630 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
35853643 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 ;
35883651 instance . use = function ( plugin ) {
35893652 plugin . installed = false ;
35903653 plugin . install . installed = false ;
3591- instance . _use ( plugin ) ;
3654+ use . call ( instance , plugin ) ;
35923655 } ;
35933656 return instance
35943657}
0 commit comments