From 41d81512bbbc3ee51320d4244aa0783f51b59f7f Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 28 Jul 2018 17:31:56 +0100 Subject: [PATCH 1/3] feat: handle async components --- packages/shared/stub-components.js | 5 +++++ test/specs/mount.spec.js | 14 ++++++++++++++ test/specs/shallow-mount.spec.js | 11 +++++++++++ 3 files changed, 30 insertions(+) diff --git a/packages/shared/stub-components.js b/packages/shared/stub-components.js index 3cc1ba207..6bc9250d3 100644 --- a/packages/shared/stub-components.js +++ b/packages/shared/stub-components.js @@ -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) { diff --git a/test/specs/mount.spec.js b/test/specs/mount.spec.js index 906dfc26b..021a32d09 100644 --- a/test/specs/mount.spec.js +++ b/test/specs/mount.spec.js @@ -162,6 +162,20 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => { expect(wrapper.html()).to.equal(`
`) }) + it('handles async components', (done) => { + const TestComponent = { + template: '
', + 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 ` + diff --git a/test/specs/shallow-mount.spec.js b/test/specs/shallow-mount.spec.js index 3b486bc27..1b061d3a9 100644 --- a/test/specs/shallow-mount.spec.js +++ b/test/specs/shallow-mount.spec.js @@ -294,6 +294,17 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { .to.equal('hey') }) + it('handles async components', () => { + const TestComponent = { + template: '
', + 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({ }) From c2b97fbfb6f48e37f03d8073a25b8af60993021a Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sat, 28 Jul 2018 18:14:51 +0100 Subject: [PATCH 2/3] test: don't run in vueVersion < 2.4 --- test/specs/mount.spec.js | 2 +- test/specs/shallow-mount.spec.js | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/test/specs/mount.spec.js b/test/specs/mount.spec.js index 021a32d09..66f072bea 100644 --- a/test/specs/mount.spec.js +++ b/test/specs/mount.spec.js @@ -162,7 +162,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => { expect(wrapper.html()).to.equal(`
`) }) - it('handles async components', (done) => { + it('handles components as dynamic imports', (done) => { const TestComponent = { template: '
', components: { diff --git a/test/specs/shallow-mount.spec.js b/test/specs/shallow-mount.spec.js index 1b061d3a9..4467fcb8c 100644 --- a/test/specs/shallow-mount.spec.js +++ b/test/specs/shallow-mount.spec.js @@ -294,16 +294,18 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { .to.equal('hey') }) - it('handles async components', () => { - const TestComponent = { - template: '
', - components: { - AsyncComponent: () => import('~resources/components/component.vue') + itDoNotRunIf( + vueVersion < 2.4, // auto resolve of default export added in 2.4 + 'handles component as dynamic import', () => { + const TestComponent = { + template: '
', + components: { + AsyncComponent: () => import('~resources/components/component.vue') + } } - } - const wrapper = shallowMount(TestComponent) - expect(wrapper.find({ name: 'AsyncComponent' }).exists()).to.equal(true) - }) + 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) { From 3a7f094e8275ccd9e860fe819855182cbe9ffc77 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Sun, 29 Jul 2018 06:08:01 +0100 Subject: [PATCH 3/3] test: only run test in vue > 2.4 --- test/specs/mount.spec.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/test/specs/mount.spec.js b/test/specs/mount.spec.js index 66f072bea..c248915db 100644 --- a/test/specs/mount.spec.js +++ b/test/specs/mount.spec.js @@ -162,19 +162,21 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => { expect(wrapper.html()).to.equal(`
`) }) - it('handles components as dynamic imports', (done) => { - const TestComponent = { - template: '
', - components: { - AsyncComponent: () => import('~resources/components/component.vue') + itDoNotRunIf( + vueVersion < 2.4, // auto resolve of default export added in 2.4 + 'handles components as dynamic imports', (done) => { + const TestComponent = { + template: '
', + components: { + AsyncComponent: () => import('~resources/components/component.vue') + } } - } - const wrapper = mount(TestComponent) - setTimeout(() => { - expect(wrapper.find(Component).exists()).to.equal(true) - done() + const wrapper = mount(TestComponent) + setTimeout(() => { + expect(wrapper.find(Component).exists()).to.equal(true) + done() + }) }) - }) it('logs if component is extended', () => { const msg =