Skip to content

Commit

Permalink
fix: handle dynamic imports (vuejs#864)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh authored and kuitos committed Aug 2, 2018
1 parent 0782f78 commit 0aa9f96
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/shared/stub-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ function stubComponents (
const componentOptions = typeof cmp === 'function'
? cmp.extendOptions
: cmp

if (!componentOptions) {
stubbedComponents[component] = createBlankStub({}, component)
return
}
// Remove cached constructor
delete componentOptions._Ctor
if (!componentOptions.name) {
Expand Down
16 changes: 16 additions & 0 deletions test/specs/mount.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,22 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => {
expect(wrapper.html()).to.equal(`<div></div>`)
})

itDoNotRunIf(
vueVersion < 2.4, // auto resolve of default export added in 2.4
'handles components as dynamic imports', (done) => {
const TestComponent = {
template: '<div><async-component /></div>',
components: {
AsyncComponent: () => import('~resources/components/component.vue')
}
}
const wrapper = mount(TestComponent)
setTimeout(() => {
expect(wrapper.find(Component).exists()).to.equal(true)
done()
})
})

it('logs if component is extended', () => {
const msg =
`[vue-test-utils]: an extended child component <ChildComponent> ` +
Expand Down
13 changes: 13 additions & 0 deletions test/specs/shallow-mount.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,19 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
.to.equal('hey')
})

itDoNotRunIf(
vueVersion < 2.4, // auto resolve of default export added in 2.4
'handles component as dynamic import', () => {
const TestComponent = {
template: '<div><async-component /></div>',
components: {
AsyncComponent: () => import('~resources/components/component.vue')
}
}
const wrapper = shallowMount(TestComponent)
expect(wrapper.find({ name: 'AsyncComponent' }).exists()).to.equal(true)
})

it('stubs components registered on localVue after multiple installs', () => {
const myPlugin = function (_Vue, opts) {
_Vue.mixin({ })
Expand Down

0 comments on commit 0aa9f96

Please sign in to comment.