@@ -165,7 +165,7 @@ describe('api: lifecycle hooks', () => {
165
165
166
166
toggle . value = false
167
167
await nextTick ( )
168
- // expect(fn).toHaveBeenCalledTimes(1) // FIXME: not called
168
+ expect ( fn ) . toHaveBeenCalledTimes ( 1 )
169
169
expect ( host . innerHTML ) . toBe ( '<!--if-->' )
170
170
} )
171
171
@@ -201,7 +201,7 @@ describe('api: lifecycle hooks', () => {
201
201
202
202
toggle . value = false
203
203
await nextTick ( )
204
- // expect(fn).toHaveBeenCalledTimes(1) // FIXME: not called
204
+ expect ( fn ) . toHaveBeenCalledTimes ( 1 )
205
205
expect ( host . innerHTML ) . toBe ( '<!--if-->' )
206
206
} )
207
207
@@ -239,29 +239,32 @@ describe('api: lifecycle hooks', () => {
239
239
240
240
toggle . value = false
241
241
await nextTick ( )
242
- // expect(fn).toHaveBeenCalledTimes(1) // FIXME: not called
242
+ expect ( fn ) . toHaveBeenCalledTimes ( 1 )
243
243
expect ( host . innerHTML ) . toBe ( '<!--if-->' )
244
244
} )
245
245
246
246
it ( 'lifecycle call order' , async ( ) => {
247
- const count = ref ( 0 )
247
+ const rootCounter = ref ( 0 )
248
+ const propsCounter = ref ( 0 )
248
249
const toggle = ref ( true )
249
250
const calls : string [ ] = [ ]
250
251
251
252
const { render } = define ( {
252
253
setup ( ) {
253
- onBeforeMount ( ( ) => calls . push ( 'onBeforeMount' ) )
254
- onMounted ( ( ) => calls . push ( 'onMounted' ) )
255
- onBeforeUpdate ( ( ) => calls . push ( 'onBeforeUpdate' ) )
256
- onUpdated ( ( ) => calls . push ( 'onUpdated' ) )
257
- onBeforeUnmount ( ( ) => calls . push ( 'onBeforeUnmount' ) )
258
- onUnmounted ( ( ) => calls . push ( 'onUnmounted' ) )
254
+ onBeforeMount ( ( ) => calls . push ( 'root onBeforeMount' ) )
255
+ onMounted ( ( ) => calls . push ( 'root onMounted' ) )
256
+ onBeforeUpdate ( ( ) => calls . push ( 'root onBeforeUpdate' ) )
257
+ onUpdated ( ( ) => calls . push ( 'root onUpdated' ) )
258
+ onBeforeUnmount ( ( ) => calls . push ( 'root onBeforeUnmount' ) )
259
+ onUnmounted ( ( ) => calls . push ( 'root onUnmounted' ) )
259
260
return ( ( ) => {
260
- const n0 = createIf (
261
+ const n0 = template ( '<p></p>' ) ( )
262
+ renderEffect ( ( ) => setText ( n0 , rootCounter . value ) )
263
+ const n1 = createIf (
261
264
( ) => toggle . value ,
262
- ( ) => createComponent ( Mid , { count : ( ) => count . value } ) ,
265
+ ( ) => createComponent ( Mid , { count : ( ) => propsCounter . value } ) ,
263
266
)
264
- return n0
267
+ return [ n0 , n1 ]
265
268
} ) ( )
266
269
} ,
267
270
} )
@@ -303,42 +306,65 @@ describe('api: lifecycle hooks', () => {
303
306
// mount
304
307
render ( )
305
308
expect ( calls ) . toEqual ( [
306
- 'onBeforeMount' ,
309
+ 'root onBeforeMount' ,
307
310
'mid onBeforeMount' ,
308
311
'child onBeforeMount' ,
309
312
'child onMounted' ,
310
313
'mid onMounted' ,
311
- 'onMounted' ,
314
+ 'root onMounted' ,
312
315
] )
313
316
314
317
calls . length = 0
315
318
316
- // update
317
- count . value ++
319
+ // props update
320
+ propsCounter . value ++
321
+ await nextTick ( )
322
+ // There are no calls in the root and mid,
323
+ // but maybe such performance would be better.
324
+ expect ( calls ) . toEqual ( [
325
+ // 'root onBeforeUpdate',
326
+ // 'mid onBeforeUpdate',
327
+ 'child onBeforeUpdate' ,
328
+ 'child onUpdated' ,
329
+ // 'mid onUpdated',
330
+ // 'root onUpdated',
331
+ ] )
332
+
333
+ calls . length = 0
334
+
335
+ // root update
336
+ rootCounter . value ++
318
337
await nextTick ( )
319
- // FIXME: not called
320
- // expect(calls).toEqual([
321
- // 'root onBeforeUpdate',
322
- // 'mid onBeforeUpdate',
323
- // 'child onBeforeUpdate',
324
- // 'child onUpdated',
325
- // 'mid onUpdated',
326
- // 'root onUpdated',
327
- // ])
338
+ // Root update events should not be passed to children.
339
+ expect ( calls ) . toEqual ( [ 'root onBeforeUpdate' , 'root onUpdated' ] )
328
340
329
341
calls . length = 0
330
342
331
343
// unmount
332
344
toggle . value = false
333
- // FIXME: not called
334
- // expect(calls).toEqual([
335
- // 'root onBeforeUnmount',
336
- // 'mid onBeforeUnmount',
337
- // 'child onBeforeUnmount',
338
- // 'child onUnmounted',
339
- // 'mid onUnmounted',
340
- // 'root onUnmounted',
341
- // ])
345
+ await nextTick ( )
346
+ expect ( calls ) . toEqual ( [
347
+ 'root onBeforeUpdate' ,
348
+ 'mid onBeforeUnmount' ,
349
+ 'child onBeforeUnmount' ,
350
+ 'child onUnmounted' ,
351
+ 'mid onUnmounted' ,
352
+ 'root onUpdated' ,
353
+ ] )
354
+
355
+ calls . length = 0
356
+
357
+ // mount
358
+ toggle . value = true
359
+ await nextTick ( )
360
+ expect ( calls ) . toEqual ( [
361
+ 'root onBeforeUpdate' ,
362
+ 'mid onBeforeMount' ,
363
+ 'child onBeforeMount' ,
364
+ 'child onMounted' ,
365
+ 'mid onMounted' ,
366
+ 'root onUpdated' ,
367
+ ] )
342
368
} )
343
369
344
370
it ( 'onRenderTracked' , async ( ) => {
@@ -458,7 +484,7 @@ describe('api: lifecycle hooks', () => {
458
484
expect ( fn ) . toHaveBeenCalledTimes ( 2 )
459
485
toggle . value = false
460
486
await nextTick ( )
461
- // expect(fn).toHaveBeenCalledTimes(4) // FIXME: not called unmounted hook
487
+ expect ( fn ) . toHaveBeenCalledTimes ( 4 )
462
488
} )
463
489
464
490
// #136
0 commit comments