File tree 2 files changed +26
-1
lines changed
test/specs/mounting-options
2 files changed +26
-1
lines changed 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