@@ -5,7 +5,7 @@ import ComponentAsAClass from '~resources/components/component-as-a-class.vue'
5
5
import { createLocalVue , config } from '~vue/test-utils'
6
6
import { config as serverConfig } from '~vue/server-test-utils'
7
7
import Vue from 'vue'
8
- import { describeWithMountingMethods } from '~resources/utils'
8
+ import { describeWithMountingMethods , vueVersion } from '~resources/utils'
9
9
import { itDoNotRunIf } from 'conditional-specs'
10
10
11
11
describeWithMountingMethods ( 'options.stub' , mountingMethod => {
@@ -133,42 +133,70 @@ describeWithMountingMethods('options.stub', mountingMethod => {
133
133
itDoNotRunIf (
134
134
mountingMethod . name === 'shallowMount' ,
135
135
'stubs nested components' , ( ) => {
136
- const GrandchildComponent = {
136
+ const GrandChildComponent = {
137
137
template : '<span />'
138
138
}
139
139
const ChildComponent = {
140
- template : '<grandchild -component />' ,
141
- components : { GrandchildComponent }
140
+ template : '<grand-child -component />' ,
141
+ components : { GrandChildComponent }
142
142
}
143
143
const TestComponent = {
144
144
template : '<child-component />' ,
145
145
components : { ChildComponent }
146
146
}
147
147
const wrapper = mountingMethod ( TestComponent , {
148
- stubs : [ 'grandchild -component' ]
148
+ stubs : [ 'grand-child -component' ]
149
149
} )
150
150
const HTML = mountingMethod . name === 'renderToString'
151
151
? wrapper
152
152
: wrapper . html ( )
153
153
expect ( HTML ) . not . to . contain ( '<span>' )
154
154
} )
155
155
156
+ itDoNotRunIf (
157
+ mountingMethod . name === 'shallowMount' || vueVersion < 2.3 ,
158
+ 'stubs nested components registered globally' , ( ) => {
159
+ const GrandChildComponent = {
160
+ render : h => h ( 'span' , [ 'hello' ] )
161
+ }
162
+ const ChildComponent = {
163
+ render : h => h ( 'grand-child-component' )
164
+ }
165
+ const TestComponent = {
166
+ render : h => h ( 'child-component' )
167
+ }
168
+ Vue . component ( 'child-component' , ChildComponent )
169
+ Vue . component ( 'grand-child-component' , GrandChildComponent )
170
+
171
+ const wrapper = mountingMethod ( TestComponent , {
172
+ stubs : {
173
+ 'grand-child-component' : true
174
+ }
175
+ } )
176
+ const HTML = mountingMethod . name === 'renderToString'
177
+ ? wrapper
178
+ : wrapper . html ( )
179
+ expect ( HTML ) . not . to . contain ( '<span>' )
180
+ delete Vue . options . components [ 'child-component' ]
181
+ delete Vue . options . components [ 'grand-child-component' ]
182
+ } )
183
+
156
184
itDoNotRunIf (
157
185
mountingMethod . name === 'shallowMount' ,
158
186
'stubs nested components on extended components' , ( ) => {
159
- const GrandchildComponent = {
187
+ const GrandChildComponent = {
160
188
template : '<span />'
161
189
}
162
190
const ChildComponent = {
163
- template : '<grandchild -component />' ,
164
- components : { GrandchildComponent }
191
+ template : '<grand-child -component />' ,
192
+ components : { GrandChildComponent }
165
193
}
166
194
const TestComponent = {
167
195
template : '<div><child-component /></div>' ,
168
196
components : { ChildComponent }
169
197
}
170
198
const wrapper = mountingMethod ( Vue . extend ( TestComponent ) , {
171
- stubs : [ 'grandchild -component' ]
199
+ stubs : [ 'grand-child -component' ]
172
200
} )
173
201
const HTML = mountingMethod . name === 'renderToString'
174
202
? wrapper
0 commit comments