From dda3333a7e0d7cb2f829d30840416ac32e95aa39 Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Sat, 12 Dec 2020 18:23:00 +0200 Subject: [PATCH] fix: does not pass data provided to mount to wrapper component --- packages/create-instance/create-instance.js | 3 ++- test/specs/mounting-options/data.spec.js | 24 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/specs/mounting-options/data.spec.js diff --git a/packages/create-instance/create-instance.js b/packages/create-instance/create-instance.js index 336c5c197..68b12774a 100644 --- a/packages/create-instance/create-instance.js +++ b/packages/create-instance/create-instance.js @@ -125,7 +125,8 @@ export default function createInstance( } // options "propsData" can only be used during instance creation with the `new` keyword - const { propsData, ...rest } = options // eslint-disable-line + // "data" should be set only on component under test to avoid reactivity issues + const { propsData, data, ...rest } = options // eslint-disable-line const Parent = _Vue.extend({ ...rest, ...parentComponentOptions diff --git a/test/specs/mounting-options/data.spec.js b/test/specs/mounting-options/data.spec.js new file mode 100644 index 000000000..1c9707195 --- /dev/null +++ b/test/specs/mounting-options/data.spec.js @@ -0,0 +1,24 @@ +import { describeWithShallowAndMount } from '~resources/utils' + +describeWithShallowAndMount('options.data', mountingMethod => { + const TestComponent = { + data: () => ({ foo: 1, bar: 2 }), + template: '
' + } + + it('correctly merges component data and data passed to mount', () => { + const wrapper = mountingMethod(TestComponent, { data: () => ({ foo: 3 }) }) + + expect(wrapper.vm.foo).toBe(3) + expect(wrapper.vm.bar).toBe(2) + }) + + it('does not fail when data is extracted to local variable', () => { + const defaultData = { foo: 3 } + + const wrapper = mountingMethod(TestComponent, { data: () => defaultData }) + + expect(wrapper.vm.foo).toBe(3) + expect(wrapper.vm.bar).toBe(2) + }) +})