@@ -3,6 +3,7 @@ import ComponentWithChild from '~resources/components/component-with-child.vue'
3
3
import ComponentWithNestedChildren from '~resources/components/component-with-nested-children.vue'
4
4
import Component from '~resources/components/component.vue'
5
5
import config from '~src/config'
6
+ import createLocalVue from '~src/create-local-vue'
6
7
7
8
describe ( 'mount.stub' , ( ) => {
8
9
let info
@@ -134,6 +135,7 @@ describe('mount.stub', () => {
134
135
}
135
136
require . cache [ require . resolve ( 'vue-template-compiler' ) ] . exports . compileToFunctions = compilerSave
136
137
} )
138
+
137
139
it ( 'does not stub component when set to false' , ( ) => {
138
140
const wrapper = mount ( ComponentWithChild , {
139
141
stubs : {
@@ -142,6 +144,76 @@ describe('mount.stub', () => {
142
144
expect ( wrapper . find ( 'span' ) . contains ( 'div' ) ) . to . equal ( true )
143
145
} )
144
146
147
+ it ( 'combines with stubs from config' , ( ) => {
148
+ const localVue = createLocalVue ( )
149
+ config . stubs [ 'time-component' ] = '<p />'
150
+ const SpanComponent = {
151
+ render : h => h ( 'span' )
152
+ }
153
+ const TimeComponent = {
154
+ render : h => h ( 'time' )
155
+ }
156
+ localVue . component ( 'span-component' , SpanComponent )
157
+ localVue . component ( 'time-component' , TimeComponent )
158
+ const TestComponent = {
159
+ render : h => h ( 'div' , [
160
+ h ( 'span-component' ) ,
161
+ h ( 'time-component' )
162
+ ] )
163
+ }
164
+
165
+ const wrapper = mount ( TestComponent , {
166
+ stubs : {
167
+ 'span-component' : '<p />'
168
+ } ,
169
+ localVue
170
+ } )
171
+ expect ( wrapper . findAll ( 'p' ) . length ) . to . equal ( 2 )
172
+ } )
173
+
174
+ it ( 'prioritize mounting options over config' , ( ) => {
175
+ const localVue = createLocalVue ( )
176
+ config . stubs [ 'time-component' ] = '<p />'
177
+ const TimeComponent = {
178
+ render : h => h ( 'time' )
179
+ }
180
+ localVue . component ( 'time-component' , TimeComponent )
181
+ const TestComponent = {
182
+ render : h => h ( 'div' , [
183
+ h ( 'time-component' )
184
+ ] )
185
+ }
186
+
187
+ const wrapper = mount ( TestComponent , {
188
+ stubs : {
189
+ 'time-component' : '<span />'
190
+ } ,
191
+ localVue
192
+ } )
193
+ expect ( wrapper . contains ( 'span' ) ) . to . equal ( true )
194
+ } )
195
+
196
+ it ( 'converts config to array if stubs is an array' , ( ) => {
197
+ const localVue = createLocalVue ( )
198
+ config . stubs [ 'time-component' ] = '<p />'
199
+ const TimeComponent = {
200
+ render : h => h ( 'time' )
201
+ }
202
+ localVue . component ( 'time-component' , TimeComponent )
203
+ const TestComponent = {
204
+ render : h => h ( 'div' , [
205
+ h ( 'time-component' )
206
+ ] )
207
+ }
208
+
209
+ const wrapper = mount ( TestComponent , {
210
+ stubs : [ 'a-component' ] ,
211
+ localVue
212
+ } )
213
+ expect ( wrapper . contains ( 'time' ) ) . to . equal ( false )
214
+ expect ( wrapper . contains ( 'p' ) ) . to . equal ( false )
215
+ } )
216
+
145
217
it ( 'throws an error when passed an invalid value as stub' , ( ) => {
146
218
const error = '[vue-test-utils]: options.stub values must be passed a string or component'
147
219
const invalidValues = [ 1 , null , [ ] , { } , NaN ]
0 commit comments