Skip to content

Commit

Permalink
fix: does not pass data provided to mount to wrapper component
Browse files Browse the repository at this point in the history
  • Loading branch information
xanf committed Dec 12, 2020
1 parent d2add54 commit 35ea4e3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions flow/options.flow.js
Expand Up @@ -3,6 +3,7 @@ declare type Options = {
attachToDocument?: boolean,
attachTo?: HTMLElement | string,
propsData?: Object,
data?: Object | Function,
mocks?: Object,
methods?: { [key: string]: Function },
slots?: SlotsObject,
Expand All @@ -20,6 +21,7 @@ declare type Options = {
declare type NormalizedOptions = {
attachTo?: HTMLElement | string,
attachToDocument?: boolean,
data?: Object | Function,
propsData?: Object,
mocks: Object,
methods: { [key: string]: Function },
Expand Down
3 changes: 2 additions & 1 deletion packages/create-instance/create-instance.js
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions 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: '<div />'
}

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)
})
})

0 comments on commit 35ea4e3

Please sign in to comment.