Skip to content

Commit 35ea4e3

Browse files
committed
fix: does not pass data provided to mount to wrapper component
1 parent d2add54 commit 35ea4e3

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

flow/options.flow.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ declare type Options = {
33
attachToDocument?: boolean,
44
attachTo?: HTMLElement | string,
55
propsData?: Object,
6+
data?: Object | Function,
67
mocks?: Object,
78
methods?: { [key: string]: Function },
89
slots?: SlotsObject,
@@ -20,6 +21,7 @@ declare type Options = {
2021
declare type NormalizedOptions = {
2122
attachTo?: HTMLElement | string,
2223
attachToDocument?: boolean,
24+
data?: Object | Function,
2325
propsData?: Object,
2426
mocks: Object,
2527
methods: { [key: string]: Function },

packages/create-instance/create-instance.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ export default function createInstance(
125125
}
126126

127127
// options "propsData" can only be used during instance creation with the `new` keyword
128-
const { propsData, ...rest } = options // eslint-disable-line
128+
// "data" should be set only on component under test to avoid reactivity issues
129+
const { propsData, data, ...rest } = options // eslint-disable-line
129130
const Parent = _Vue.extend({
130131
...rest,
131132
...parentComponentOptions
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { describeWithShallowAndMount } from '~resources/utils'
2+
3+
describeWithShallowAndMount('options.data', mountingMethod => {
4+
const TestComponent = {
5+
data: () => ({ foo: 1, bar: 2 }),
6+
template: '<div />'
7+
}
8+
9+
it('correctly merges component data and data passed to mount', () => {
10+
const wrapper = mountingMethod(TestComponent, { data: () => ({ foo: 3 }) })
11+
12+
expect(wrapper.vm.foo).toBe(3)
13+
expect(wrapper.vm.bar).toBe(2)
14+
})
15+
16+
it('does not fail when data is extracted to local variable', () => {
17+
const defaultData = { foo: 3 }
18+
19+
const wrapper = mountingMethod(TestComponent, { data: () => defaultData })
20+
21+
expect(wrapper.vm.foo).toBe(3)
22+
expect(wrapper.vm.bar).toBe(2)
23+
})
24+
})

0 commit comments

Comments
 (0)