@@ -169,6 +169,110 @@ describeWithShallowAndMount('setProps', mountingMethod => {
169
169
expect ( wrapper . vm . data ) . to . equal ( '1,2,3,4,5' )
170
170
} )
171
171
172
+ it ( 'runs computed when prop is object' , ( ) => {
173
+ class TestClass {
174
+ constructor ( text ) {
175
+ this . _text = text
176
+ }
177
+
178
+ get text ( ) {
179
+ return this . _text
180
+ }
181
+
182
+ set text ( text ) {
183
+ this . _text = text
184
+ }
185
+ }
186
+
187
+ const TestComponent = {
188
+ template : `<div id="app">
189
+ <div class="shallow">{{ shallowObjText }}</div>
190
+ <div class="deep">{{ deepObjText }}</div>
191
+ <div class="class">{{ classText }}</div>
192
+ </div>` ,
193
+ props : {
194
+ shallowObj : Object ,
195
+ deepObj : Object ,
196
+ classInstance : TestClass
197
+ } ,
198
+ computed : {
199
+ shallowObjText ( ) {
200
+ return this . shallowObj . text
201
+ } ,
202
+ deepObjText ( ) {
203
+ return this . deepObj . obj . text
204
+ } ,
205
+ classText ( ) {
206
+ return this . classInstance . text
207
+ }
208
+ }
209
+ }
210
+
211
+ const shallowObj = {
212
+ text : 'initial shallow'
213
+ }
214
+ const deepObj = {
215
+ obj : {
216
+ text : 'initial deep'
217
+ }
218
+ }
219
+ const classInstance = new TestClass ( 'initial class' )
220
+ const wrapper = mountingMethod ( TestComponent , {
221
+ propsData : { shallowObj, deepObj, classInstance }
222
+ } )
223
+ const shallowWraper = wrapper . find ( '.shallow' )
224
+ const deepWrapper = wrapper . find ( '.deep' )
225
+ const classWrapper = wrapper . find ( '.class' )
226
+
227
+ expect ( shallowWraper . text ( ) ) . to . equal ( 'initial shallow' )
228
+ expect ( deepWrapper . text ( ) ) . to . equal ( 'initial deep' )
229
+ expect ( classWrapper . text ( ) ) . to . equal ( 'initial class' )
230
+
231
+ shallowObj . text = 'updated shallow'
232
+ deepObj . obj . text = 'updated deep'
233
+ classInstance . text = 'updated class'
234
+ wrapper . setProps ( { shallowObj, deepObj, classInstance } )
235
+ expect ( shallowWraper . text ( ) ) . to . equal ( 'updated shallow' )
236
+ expect ( deepWrapper . text ( ) ) . to . equal ( 'updated deep' )
237
+ expect ( classWrapper . text ( ) ) . to . equal ( 'updated class' )
238
+ } )
239
+
240
+ it ( 'runs watcher when prop is object' , ( ) => {
241
+ const TestComponent = {
242
+ template : `<div id="app">
243
+ <div class="watch">{{ watchText }}</div>
244
+ </div>` ,
245
+ props : {
246
+ obj : Object
247
+ } ,
248
+ data : ( ) => ( {
249
+ watchText : 'initial'
250
+ } ) ,
251
+ watch : {
252
+ 'obj.text' : 'execute'
253
+ } ,
254
+ methods : {
255
+ execute ( ) {
256
+ this . watchText = 'updated'
257
+ }
258
+ }
259
+ }
260
+
261
+ const obj = {
262
+ text : 'initial shallow'
263
+ }
264
+ const wrapper = mountingMethod ( TestComponent , {
265
+ propsData : { obj }
266
+ } )
267
+ const watchWrapper = wrapper . find ( '.watch' )
268
+
269
+ expect ( watchWrapper . text ( ) ) . to . equal ( 'initial' )
270
+
271
+ obj . text = 'updated shallow'
272
+ wrapper . setProps ( { obj } )
273
+ expect ( watchWrapper . text ( ) ) . to . equal ( 'updated' )
274
+ } )
275
+
172
276
it ( 'throws an error if node is not a Vue instance' , ( ) => {
173
277
const message = 'wrapper.setProps() can only be called on a Vue instance'
174
278
const compiled = compileToFunctions ( '<div><p></p></div>' )
0 commit comments