File tree Expand file tree Collapse file tree 3 files changed +28
-1
lines changed
test/specs/mounting-options Expand file tree Collapse file tree 3 files changed +28
-1
lines changed Original file line number Diff line number Diff 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 = {
2021declare type NormalizedOptions = {
2122 attachTo ?: HTMLElement | string ,
2223 attachToDocument ?: boolean ,
24+ data ?: Object | Function ,
2325 propsData ?: Object ,
2426 mocks : Object ,
2527 methods : { [ key : string ] : Function } ,
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+ } )
You can’t perform that action at this time.
0 commit comments