@@ -36,6 +36,7 @@ function stubLifeCycleEvents (component) {
36
36
function isValidStub ( stub ) {
37
37
return ! ! stub &&
38
38
( typeof stub === 'string' ||
39
+ ( stub === true ) ||
39
40
( typeof stub === 'object' &&
40
41
typeof stub . render === 'function' ) )
41
42
}
@@ -67,35 +68,47 @@ function createBlankStub (originalComponent) {
67
68
}
68
69
69
70
function stubComponents ( component , stubs ) {
70
- Object . keys ( stubs ) . forEach ( function ( stub ) {
71
- if ( ! isValidStub ( stubs [ stub ] ) ) {
72
- throwError ( 'options.stub values must be passed a string or component' ) ;
73
- }
74
-
75
- if ( ! component . components ) {
76
- component . components = { } ;
77
- }
71
+ if ( ! component . components ) {
72
+ component . components = { } ;
73
+ }
78
74
79
- if ( component . components [ stub ] ) {
80
- // Remove cached constructor
81
- delete component . components [ stub ] . _Ctor ;
82
- if ( typeof stubs [ stub ] === 'string' ) {
83
- component . components [ stub ] = createStubFromString ( stubs [ stub ] , component . components [ stub ] ) ;
84
- stubLifeCycleEvents ( component . components [ stub ] ) ;
85
- } else {
86
- component . components [ stub ] = Object . assign ( { } , stubs [ stub ] ,
87
- { name : component . components [ stub ] . name } ) ;
75
+ if ( Array . isArray ( stubs ) ) {
76
+ stubs . forEach ( function ( stub ) {
77
+ if ( typeof stub !== 'string' ) {
78
+ throwError ( 'each item in options.stub must be a string' ) ;
88
79
}
89
- } else {
90
- if ( typeof stubs [ stub ] === 'string' ) {
91
- component . components [ stub ] = Object . assign ( { } , vueTemplateCompiler . compileToFunctions ( stubs [ stub ] ) ) ;
92
- stubLifeCycleEvents ( component . components [ stub ] ) ;
80
+ component . components [ stub ] = createBlankStub ( { } ) ;
81
+ } ) ;
82
+ } else {
83
+ Object . keys ( stubs ) . forEach ( function ( stub ) {
84
+ if ( ! isValidStub ( stubs [ stub ] ) ) {
85
+ throwError ( 'options.stub values must be passed a string or component' ) ;
86
+ }
87
+ if ( stubs [ stub ] === true ) {
88
+ component . components [ stub ] = createBlankStub ( { } ) ;
89
+ return
90
+ }
91
+ if ( component . components [ stub ] ) {
92
+ // Remove cached constructor
93
+ delete component . components [ stub ] . _Ctor ;
94
+ if ( typeof stubs [ stub ] === 'string' ) {
95
+ component . components [ stub ] = createStubFromString ( stubs [ stub ] , component . components [ stub ] ) ;
96
+ stubLifeCycleEvents ( component . components [ stub ] ) ;
97
+ } else {
98
+ component . components [ stub ] = Object . assign ( { } , stubs [ stub ] ,
99
+ { name : component . components [ stub ] . name } ) ;
100
+ }
93
101
} else {
94
- component . components [ stub ] = Object . assign ( { } , stubs [ stub ] ) ;
102
+ if ( typeof stubs [ stub ] === 'string' ) {
103
+ component . components [ stub ] = Object . assign ( { } , vueTemplateCompiler . compileToFunctions ( stubs [ stub ] ) ) ;
104
+ stubLifeCycleEvents ( component . components [ stub ] ) ;
105
+ } else {
106
+ component . components [ stub ] = Object . assign ( { } , stubs [ stub ] ) ;
107
+ }
95
108
}
96
- }
97
- Vue . config . ignoredElements . push ( stub ) ;
98
- } ) ;
109
+ Vue . config . ignoredElements . push ( stub ) ;
110
+ } ) ;
111
+ }
99
112
}
100
113
101
114
function stubAllComponents ( component ) {
@@ -645,7 +658,9 @@ Wrapper.prototype.is = function is (selector) {
645
658
if ( ! this . isVueComponent ) {
646
659
return false
647
660
}
648
- // TODO: Throw error if component does not have name
661
+ if ( typeof selector . name !== 'string' ) {
662
+ throwError ( 'a Component used as a selector must have a name property' ) ;
663
+ }
649
664
return vmCtorMatchesName ( this . vm , selector . name )
650
665
}
651
666
return this . element . getAttribute && this . element . matches ( selector )
@@ -706,7 +721,9 @@ Wrapper.prototype.setProps = function setProps (data) {
706
721
Object . keys ( data ) . forEach ( function ( key ) {
707
722
// $FlowIgnore : Problem with possibly null this.vm
708
723
this$1 . vm . _props [ key ] = data [ key ] ;
709
- // $FlowIgnore : Problem with possibly null this.vm
724
+ } ) ;
725
+ Object . keys ( data ) . forEach ( function ( key ) {
726
+ // $FlowIgnore : Problem with possibly null this.vm
710
727
this$1 . vm . _watchers . forEach ( function ( watcher ) {
711
728
if ( watcher . expression === key ) { watcher . run ( ) ; }
712
729
} ) ;
@@ -837,11 +854,11 @@ function addSlots (vm, slots) {
837
854
838
855
//
839
856
840
- function addGlobals ( globals ) {
857
+ function createInterceptPlugin ( interceptedProperties ) {
841
858
return {
842
859
install : function ( Vue$$1 ) {
843
- Object . keys ( globals ) . forEach ( function ( key ) {
844
- Vue$$1 . prototype [ key ] = globals [ key ] ;
860
+ Object . keys ( interceptedProperties ) . forEach ( function ( key ) {
861
+ Vue$$1 . prototype [ key ] = interceptedProperties [ key ] ;
845
862
} ) ;
846
863
}
847
864
}
@@ -886,15 +903,17 @@ function createConstructor (component, options) {
886
903
addProvide ( component , options ) ;
887
904
}
888
905
889
- if ( options . stub ) {
890
- stubComponents ( component , options . stub ) ;
906
+ if ( options . stubs ) {
907
+ stubComponents ( component , options . stubs ) ;
891
908
}
892
909
893
910
var Constructor = vue . extend ( component ) ;
894
911
895
912
if ( options . intercept ) {
896
- var globals = addGlobals ( options . intercept ) ;
897
- Constructor . use ( globals ) ;
913
+ // creates a plugin that adds properties, and then install on local Constructor
914
+ // this does not affect the base Vue class
915
+ var interceptPlugin = createInterceptPlugin ( options . intercept ) ;
916
+ Constructor . use ( interceptPlugin ) ;
898
917
}
899
918
900
919
var vm = new Constructor ( options ) ;
@@ -945,10 +964,11 @@ function mount (component, options) {
945
964
throwError ( 'window is undefined, vue-test-utils needs to be run in a browser environment.\n You can run the tests in node using JSDOM' ) ;
946
965
}
947
966
967
+ var componentToMount = options . clone === false ? component : lodash . cloneDeep ( component ) ;
948
968
// Remove cached constructor
949
- delete component . _Ctor ;
969
+ delete componentToMount . _Ctor ;
950
970
951
- var vm = createConstructor ( component , options ) ;
971
+ var vm = createConstructor ( componentToMount , options ) ;
952
972
953
973
if ( options . attachToDocument ) {
954
974
vm . $mount ( createElement ( ) ) ;
0 commit comments