Skip to content

Commit 4e739bd

Browse files
authored
fix: handle dynamic imports (#864)
1 parent fdcea04 commit 4e739bd

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

Diff for: packages/shared/stub-components.js

+5
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ function stubComponents (
202202
const componentOptions = typeof cmp === 'function'
203203
? cmp.extendOptions
204204
: cmp
205+
206+
if (!componentOptions) {
207+
stubbedComponents[component] = createBlankStub({}, component)
208+
return
209+
}
205210
// Remove cached constructor
206211
delete componentOptions._Ctor
207212
if (!componentOptions.name) {

Diff for: test/specs/mount.spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,22 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
162162
expect(wrapper.html()).to.equal(`<div></div>`)
163163
})
164164

165+
itDoNotRunIf(
166+
vueVersion < 2.4, // auto resolve of default export added in 2.4
167+
'handles components as dynamic imports', (done) => {
168+
const TestComponent = {
169+
template: '<div><async-component /></div>',
170+
components: {
171+
AsyncComponent: () => import('~resources/components/component.vue')
172+
}
173+
}
174+
const wrapper = mount(TestComponent)
175+
setTimeout(() => {
176+
expect(wrapper.find(Component).exists()).to.equal(true)
177+
done()
178+
})
179+
})
180+
165181
it('logs if component is extended', () => {
166182
const msg =
167183
`[vue-test-utils]: an extended child component <ChildComponent> ` +

Diff for: test/specs/shallow-mount.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,19 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
294294
.to.equal('hey')
295295
})
296296

297+
itDoNotRunIf(
298+
vueVersion < 2.4, // auto resolve of default export added in 2.4
299+
'handles component as dynamic import', () => {
300+
const TestComponent = {
301+
template: '<div><async-component /></div>',
302+
components: {
303+
AsyncComponent: () => import('~resources/components/component.vue')
304+
}
305+
}
306+
const wrapper = shallowMount(TestComponent)
307+
expect(wrapper.find({ name: 'AsyncComponent' }).exists()).to.equal(true)
308+
})
309+
297310
it('stubs components registered on localVue after multiple installs', () => {
298311
const myPlugin = function (_Vue, opts) {
299312
_Vue.mixin({ })

0 commit comments

Comments
 (0)