Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions flow/options.flow.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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)
})
})