File tree Expand file tree Collapse file tree 3 files changed +47
-3
lines changed Expand file tree Collapse file tree 3 files changed +47
-3
lines changed Original file line number Diff line number Diff line change 1
- import { getCurrentInstance } from 'vue'
1
+ import { getCurrentInstance , reactive } from 'vue'
2
2
3
3
export const createDataMixin = ( data : Record < string , unknown > ) => {
4
4
return {
5
5
created ( ) {
6
6
for ( const [ k , v ] of Object . entries ( data ) ) {
7
- getCurrentInstance ( ) ! . data = { ...getCurrentInstance ( ) ! . data , [ k ] : v }
7
+ getCurrentInstance ( ) ! . data = reactive ( {
8
+ ...getCurrentInstance ( ) ! . data ,
9
+ [ k ] : v
10
+ } )
8
11
}
9
12
}
10
13
}
Original file line number Diff line number Diff line change @@ -35,7 +35,6 @@ import { attachEmitListener } from './emit'
35
35
import { createDataMixin } from './dataMixin'
36
36
import { MOUNT_COMPONENT_REF , MOUNT_PARENT_NAME } from './constants'
37
37
import { createStub , stubComponents } from './stubs'
38
- import { hyphenate } from './utils/vueShared'
39
38
40
39
// NOTE this should come from `vue`
41
40
type PublicProps = VNodeProps & AllowedComponentProps & ComponentCustomProps
Original file line number Diff line number Diff line change @@ -123,4 +123,46 @@ describe('setData', () => {
123
123
'Cannot add property count'
124
124
)
125
125
} )
126
+
127
+ // https://github.com/vuejs/vue-test-utils-next/issues/538
128
+ it ( 'updates data set via data mounting option using setData' , async ( ) => {
129
+ const Comp = defineComponent <
130
+ { } ,
131
+ { } ,
132
+ { field : number | null } ,
133
+ { isFieldNull : any }
134
+ > ( {
135
+ template : `
136
+ <div>{{ isFieldNull ? 'It is null' : 'It is not null' }}</div>
137
+ ` ,
138
+ data ( ) {
139
+ return {
140
+ field : null
141
+ }
142
+ } ,
143
+ computed : {
144
+ isFieldNull ( ) {
145
+ return this . field === null
146
+ }
147
+ }
148
+ } )
149
+
150
+ const wrapper = mount ( Comp , {
151
+ data ( ) {
152
+ return {
153
+ field : null
154
+ }
155
+ }
156
+ } )
157
+
158
+ expect ( wrapper . vm . isFieldNull ) . toBe ( true )
159
+ expect ( wrapper . html ( ) ) . toContain ( 'It is null' )
160
+
161
+ await wrapper . setData ( { field : 10 } )
162
+ await wrapper . vm . $nextTick ( )
163
+
164
+ expect ( wrapper . html ( ) ) . toContain ( 'It is not null' )
165
+ expect ( wrapper . vm . field ) . toEqual ( 10 )
166
+ expect ( wrapper . vm . isFieldNull ) . toBe ( false )
167
+ } )
126
168
} )
You can’t perform that action at this time.
0 commit comments