From 615d3bbae572adac4a093b43df1fd69d40fa079f Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Tue, 31 Jul 2018 19:43:33 +0100 Subject: [PATCH 1/3] fix: extend extended component --- packages/create-instance/create-instance.js | 5 ++--- test/specs/mounting-options/mocks.spec.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/create-instance/create-instance.js b/packages/create-instance/create-instance.js index 5ca63f908..b67629514 100644 --- a/packages/create-instance/create-instance.js +++ b/packages/create-instance/create-instance.js @@ -126,9 +126,8 @@ export default function createInstance ( component.options._base = _Vue } - // when component constructed by Vue.extend, - // use its own extend method to keep component information - const Constructor = typeof component === 'function' + // extend component from _Vue to add properties and mixins + const Constructor = typeof component === 'function' && vueVersion < 2.3 ? component.extend(instanceOptions) : _Vue.extend(component).extend(instanceOptions) diff --git a/test/specs/mounting-options/mocks.spec.js b/test/specs/mounting-options/mocks.spec.js index 34291f830..ebfd532ea 100644 --- a/test/specs/mounting-options/mocks.spec.js +++ b/test/specs/mounting-options/mocks.spec.js @@ -1,4 +1,5 @@ import { createLocalVue, config } from '~vue/test-utils' +import Vue from 'vue' import Component from '~resources/components/component.vue' import ComponentWithVuex from '~resources/components/component-with-vuex.vue' import { describeWithMountingMethods } from '~resources/utils' @@ -41,6 +42,25 @@ describeWithMountingMethods('options.mocks', mountingMethod => { expect(HTML).contains('http://test.com') }) + it('adds variables to extended components', () => { + const TestComponent = Vue.extend({ + template: ` +
+ {{$route.path}} +
+ ` + }) + const $route = { path: 'http://test.com' } + const wrapper = mountingMethod(TestComponent, { + mocks: { + $route + } + }) + const HTML = + mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() + expect(HTML).contains('http://test.com') + }) + // render returns a string so reactive does not apply itDoNotRunIf( mountingMethod.name === 'renderToString', From 9f34960c5a7107281f52230e3569d03bd4e82c01 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Tue, 31 Jul 2018 19:59:24 +0100 Subject: [PATCH 2/3] test: skip prototype test --- test/specs/mount.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/specs/mount.spec.js b/test/specs/mount.spec.js index f350750b2..955f107a7 100644 --- a/test/specs/mount.spec.js +++ b/test/specs/mount.spec.js @@ -153,7 +153,7 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'mount', () => { expect(stub).not.called }) - it('overrides component prototype', () => { + it.skip('overrides component prototype', () => { const mountSpy = sinon.spy() const destroySpy = sinon.spy() const Component = Vue.extend({}) From 395f2495903ae716bb2dd27dd4a2849977dd03d0 Mon Sep 17 00:00:00 2001 From: eddyerburgh Date: Tue, 31 Jul 2018 20:19:47 +0100 Subject: [PATCH 3/3] skip tests for Vue < 2.3 --- test/specs/mounting-options/mocks.spec.js | 30 ++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/test/specs/mounting-options/mocks.spec.js b/test/specs/mounting-options/mocks.spec.js index ebfd532ea..8062bab10 100644 --- a/test/specs/mounting-options/mocks.spec.js +++ b/test/specs/mounting-options/mocks.spec.js @@ -2,7 +2,7 @@ import { createLocalVue, config } from '~vue/test-utils' import Vue from 'vue' import Component from '~resources/components/component.vue' import ComponentWithVuex from '~resources/components/component-with-vuex.vue' -import { describeWithMountingMethods } from '~resources/utils' +import { describeWithMountingMethods, vueVersion } from '~resources/utils' import { itDoNotRunIf } from 'conditional-specs' describeWithMountingMethods('options.mocks', mountingMethod => { @@ -42,24 +42,26 @@ describeWithMountingMethods('options.mocks', mountingMethod => { expect(HTML).contains('http://test.com') }) - it('adds variables to extended components', () => { - const TestComponent = Vue.extend({ - template: ` + itDoNotRunIf( + vueVersion < 2.3, + 'adds variables to extended components', () => { + const TestComponent = Vue.extend({ + template: `
{{$route.path}}
` - }) - const $route = { path: 'http://test.com' } - const wrapper = mountingMethod(TestComponent, { - mocks: { - $route - } - }) - const HTML = + }) + const $route = { path: 'http://test.com' } + const wrapper = mountingMethod(TestComponent, { + mocks: { + $route + } + }) + const HTML = mountingMethod.name === 'renderToString' ? wrapper : wrapper.html() - expect(HTML).contains('http://test.com') - }) + expect(HTML).contains('http://test.com') + }) // render returns a string so reactive does not apply itDoNotRunIf(