Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle async components #864

Merged
merged 3 commits into from
Jul 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -162,6 +162,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