@@ -2965,6 +2965,12 @@ WrapperArray.prototype.update = function update () {
2965
2965
this . wrappers . forEach ( function ( wrapper ) { return wrapper . update ( ) ; } ) ;
2966
2966
} ;
2967
2967
2968
+ WrapperArray . prototype . destroy = function destroy ( ) {
2969
+ this . throwErrorIfWrappersIsEmpty ( 'destroy' ) ;
2970
+
2971
+ this . wrappers . forEach ( function ( wrapper ) { return wrapper . destroy ( ) ; } ) ;
2972
+ } ;
2973
+
2968
2974
//
2969
2975
var ErrorWrapper = function ErrorWrapper ( selector ) {
2970
2976
this . selector = selector ;
@@ -3062,6 +3068,10 @@ ErrorWrapper.prototype.update = function update () {
3062
3068
throwError ( ( "find did not return " + ( this . selector ) + ", cannot call update() on empty Wrapper" ) ) ;
3063
3069
} ;
3064
3070
3071
+ ErrorWrapper . prototype . destroy = function destroy ( ) {
3072
+ throwError ( ( "find did not return " + ( this . selector ) + ", cannot call destroy() on empty Wrapper" ) ) ;
3073
+ } ;
3074
+
3065
3075
//
3066
3076
3067
3077
var Wrapper = function Wrapper ( vnode , update , options ) {
@@ -3142,6 +3152,8 @@ Wrapper.prototype.hasAttribute = function hasAttribute (attribute, value) {
3142
3152
* Asserts wrapper has a class name
3143
3153
*/
3144
3154
Wrapper . prototype . hasClass = function hasClass ( className ) {
3155
+ var this$1 = this ;
3156
+
3145
3157
var targetClass = className ;
3146
3158
3147
3159
if ( typeof targetClass !== 'string' ) {
@@ -3153,7 +3165,11 @@ Wrapper.prototype.hasClass = function hasClass (className) {
3153
3165
targetClass = this . vm . $style [ targetClass ] ;
3154
3166
}
3155
3167
3156
- return ! ! ( this . element && this . element . classList . contains ( targetClass ) )
3168
+ var containsAllClasses = targetClass
3169
+ . split ( ' ' )
3170
+ . every ( function ( target ) { return this$1 . element . classList . contains ( target ) ; } ) ;
3171
+
3172
+ return ! ! ( this . element && containsAllClasses )
3157
3173
} ;
3158
3174
3159
3175
/**
@@ -3434,6 +3450,21 @@ Wrapper.prototype.text = function text () {
3434
3450
return this . element . textContent
3435
3451
} ;
3436
3452
3453
+ /**
3454
+ * Calls destroy on vm
3455
+ */
3456
+ Wrapper . prototype . destroy = function destroy ( ) {
3457
+ if ( ! this . isVueComponent ) {
3458
+ throwError ( 'wrapper.destroy() can only be called on a Vue instance' ) ;
3459
+ }
3460
+
3461
+ if ( this . element . parentNode ) {
3462
+ this . element . parentNode . removeChild ( this . element ) ;
3463
+ }
3464
+ // $FlowIgnore
3465
+ this . vm . $destroy ( ) ;
3466
+ } ;
3467
+
3437
3468
/**
3438
3469
* Dispatches a DOM event on wrapper
3439
3470
*/
@@ -3578,10 +3609,10 @@ function addSlots (vm, slots) {
3578
3609
}
3579
3610
3580
3611
//
3581
-
3582
3612
function addMocks ( mockedProperties , Vue$$1 ) {
3583
3613
Object . keys ( mockedProperties ) . forEach ( function ( key ) {
3584
3614
Vue$$1 . prototype [ key ] = mockedProperties [ key ] ;
3615
+ Vue . util . defineReactive ( Vue$$1 , key , mockedProperties [ key ] ) ;
3585
3616
} ) ;
3586
3617
}
3587
3618
@@ -3629,23 +3660,77 @@ function compileTemplate (component) {
3629
3660
3630
3661
//
3631
3662
3632
- function createConstructor ( component , options ) {
3633
- var vue = options . localVue || Vue ;
3663
+ function createLocalVue ( ) {
3664
+ var instance = Vue . extend ( ) ;
3665
+
3666
+ // clone global APIs
3667
+ Object . keys ( Vue ) . forEach ( function ( key ) {
3668
+ if ( ! instance . hasOwnProperty ( key ) ) {
3669
+ var original = Vue [ key ] ;
3670
+ instance [ key ] = typeof original === 'object'
3671
+ ? cloneDeep_1 ( original )
3672
+ : original ;
3673
+ }
3674
+ } ) ;
3634
3675
3635
- if ( options . context ) {
3636
- if ( ! component . functional ) {
3637
- throwError ( 'mount.context can only be used when mounting a functional component' ) ;
3676
+ // config is not enumerable
3677
+ instance . config = cloneDeep_1 ( Vue . config ) ;
3678
+
3679
+ // option merge strategies need to be exposed by reference
3680
+ // so that merge strats registered by plguins can work properly
3681
+ instance . config . optionMergeStrategies = Vue . config . optionMergeStrategies ;
3682
+
3683
+ // make sure all extends are based on this instance.
3684
+ // this is important so that global components registered by plugins,
3685
+ // e.g. router-link are created using the correct base constructor
3686
+ instance . options . _base = instance ;
3687
+
3688
+ // compat for vue-router < 2.7.1 where it does not allow multiple installs
3689
+ var use = instance . use ;
3690
+ instance . use = function ( plugin ) {
3691
+ var rest = [ ] , len = arguments . length - 1 ;
3692
+ while ( len -- > 0 ) rest [ len ] = arguments [ len + 1 ] ;
3693
+
3694
+ if ( plugin . installed === true ) {
3695
+ plugin . installed = false ;
3696
+ }
3697
+ if ( plugin . install && plugin . install . installed === true ) {
3698
+ plugin . install . installed = false ;
3638
3699
}
3700
+ use . call . apply ( use , [ instance , plugin ] . concat ( rest ) ) ;
3701
+ } ;
3702
+ return instance
3703
+ }
3639
3704
3640
- if ( typeof options . context !== 'object' ) {
3705
+ //
3706
+
3707
+ function createConstructor (
3708
+ component ,
3709
+ options
3710
+ ) {
3711
+ var vue = options . localVue || createLocalVue ( ) ;
3712
+
3713
+ if ( options . mocks ) {
3714
+ addMocks ( options . mocks , vue ) ;
3715
+ }
3716
+
3717
+ if ( component . functional ) {
3718
+ if ( options . context && typeof options . context !== 'object' ) {
3641
3719
throwError ( 'mount.context must be an object' ) ;
3642
3720
}
3643
3721
var clonedComponent = cloneDeep_1 ( component ) ;
3644
3722
component = {
3645
3723
render : function render ( h ) {
3646
- return h ( clonedComponent , options . context )
3724
+ return h (
3725
+ clonedComponent ,
3726
+ options . context || component . FunctionalRenderContext
3727
+ )
3647
3728
}
3648
3729
} ;
3730
+ } else if ( options . context ) {
3731
+ throwError (
3732
+ 'mount.context can only be used when mounting a functional component'
3733
+ ) ;
3649
3734
}
3650
3735
3651
3736
if ( options . provide ) {
@@ -3662,10 +3747,6 @@ function createConstructor (component, options) {
3662
3747
3663
3748
var Constructor = vue . extend ( component ) ;
3664
3749
3665
- if ( options . mocks ) {
3666
- addMocks ( options . mocks , Constructor ) ;
3667
- }
3668
-
3669
3750
var vm = new Constructor ( options ) ;
3670
3751
3671
3752
addAttrs ( vm , options . attrs ) ;
@@ -3747,46 +3828,6 @@ function shallow (component, options) {
3747
3828
3748
3829
//
3749
3830
3750
- function createLocalVue ( ) {
3751
- var instance = Vue . extend ( ) ;
3752
-
3753
- // clone global APIs
3754
- Object . keys ( Vue ) . forEach ( function ( key ) {
3755
- if ( ! instance . hasOwnProperty ( key ) ) {
3756
- var original = Vue [ key ] ;
3757
- instance [ key ] = typeof original === 'object'
3758
- ? cloneDeep_1 ( original )
3759
- : original ;
3760
- }
3761
- } ) ;
3762
-
3763
- // config is not enumerable
3764
- instance . config = cloneDeep_1 ( Vue . config ) ;
3765
-
3766
- // option merge strategies need to be exposed by reference
3767
- // so that merge strats registered by plguins can work properly
3768
- instance . config . optionMergeStrategies = Vue . config . optionMergeStrategies ;
3769
-
3770
- // make sure all extends are based on this instance.
3771
- // this is important so that global components registered by plugins,
3772
- // e.g. router-link are created using the correct base constructor
3773
- instance . options . _base = instance ;
3774
-
3775
- // compat for vue-router < 2.7.1 where it does not allow multiple installs
3776
- var use = instance . use ;
3777
- instance . use = function ( plugin ) {
3778
- var rest = [ ] , len = arguments . length - 1 ;
3779
- while ( len -- > 0 ) rest [ len ] = arguments [ len + 1 ] ;
3780
-
3781
- plugin . installed = false ;
3782
- plugin . install . installed = false ;
3783
- use . call . apply ( use , [ instance , plugin ] . concat ( rest ) ) ;
3784
- } ;
3785
- return instance
3786
- }
3787
-
3788
- //
3789
-
3790
3831
function getRealChild ( vnode ) {
3791
3832
var compOptions = vnode && vnode . componentOptions ;
3792
3833
if ( compOptions && compOptions . Ctor . options . abstract ) {
0 commit comments