Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: does not pass data provided to mount to wrapper component #1750

Merged
merged 1 commit into from Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
})
})