File tree 3 files changed +28
-1
lines changed
test/specs/mounting-options
3 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ declare type Options = {
3
3
attachToDocument ?: boolean ,
4
4
attachTo ?: HTMLElement | string ,
5
5
propsData ?: Object ,
6
+ data ?: Object | Function ,
6
7
mocks ?: Object ,
7
8
methods ?: { [ key : string ] : Function } ,
8
9
slots ?: SlotsObject ,
@@ -20,6 +21,7 @@ declare type Options = {
20
21
declare type NormalizedOptions = {
21
22
attachTo ?: HTMLElement | string ,
22
23
attachToDocument ?: boolean ,
24
+ data ?: Object | Function ,
23
25
propsData ?: Object ,
24
26
mocks : Object ,
25
27
methods : { [ key : string ] : Function } ,
Original file line number Diff line number Diff line change @@ -125,7 +125,8 @@ export default function createInstance(
125
125
}
126
126
127
127
// 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
129
130
const Parent = _Vue . extend ( {
130
131
...rest ,
131
132
...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