@@ -71,6 +71,19 @@ describe('init mpvue with lifecycle', function () {
71
71
} ,
72
72
onPageScroll ( ) {
73
73
onLifecycle . push ( `pageScroll${ key } ` )
74
+ } ,
75
+ // custom component lifecycle
76
+ attached ( ) {
77
+ onLifecycle . push ( `attached${ key } ` )
78
+ } ,
79
+ ready ( ) {
80
+ onLifecycle . push ( `ready${ key } ` )
81
+ } ,
82
+ moved ( ) {
83
+ onLifecycle . push ( `moved${ key } ` )
84
+ } ,
85
+ detached ( ) {
86
+ onLifecycle . push ( `detached${ key } ` )
74
87
}
75
88
}
76
89
}
@@ -237,4 +250,101 @@ describe('init mpvue with lifecycle', function () {
237
250
expect ( app . $mp . status ) . toEqual ( 'unload' )
238
251
expect ( onLifecycle ) . toEqual ( [ 'beforeCreate' , 'created' , 'onLoad' , 'onShow' , 'onReady' , 'beforeMount' , 'mounted' , 'pullDownRefresh' , 'reachBottom' , 'shareAppMessage' , 'pageScroll' , 'unload' ] )
239
252
} )
253
+
254
+ it ( 'Component with render' , function ( ) {
255
+ const options = Object . assign ( getComponentOptions ( ) , {
256
+ mpType : 'component' ,
257
+ render ( ) {
258
+ var _vm = this
259
+ var _h = _vm . $createElement
260
+ var _c = _vm . _self . _c || _h
261
+ return _c ( 'div' , {
262
+ staticClass : 'container'
263
+ } , [ ] , 1 )
264
+ }
265
+ } )
266
+
267
+ const app = createInstance ( options )
268
+ app . $mount ( )
269
+ expect ( onLifecycle ) . toEqual ( [ 'beforeCreate' , 'created' , 'attached' , 'ready' , 'beforeMount' , 'mounted' ] )
270
+ expect ( ! ! app . $mp . page ) . toEqual ( true )
271
+ expect ( app . $mp . mpType ) . toEqual ( 'component' )
272
+ expect ( app . $mp . status ) . toEqual ( 'ready' )
273
+ } )
274
+
275
+ it ( 'Component with component' , function ( ) {
276
+ const warpOptions = Object . assign ( getComponentOptions ( '-warp' ) , {
277
+ render ( ) {
278
+ var _vm = this
279
+ var _h = _vm . $createElement
280
+ var _c = _vm . _self . _c || _h
281
+ return _c ( 'div' , {
282
+ staticClass : 'container'
283
+ } , [ _vm . _v ( 'warp component' ) ] , 1 )
284
+ }
285
+ } )
286
+ const options = Object . assign ( getComponentOptions ( ) , {
287
+ mpType : 'component' ,
288
+ components : {
289
+ warp : warpOptions
290
+ } ,
291
+ render ( ) {
292
+ var _vm = this
293
+ var _h = _vm . $createElement
294
+ var _c = _vm . _self . _c || _h
295
+ return _c ( 'div' , {
296
+ staticClass : 'container'
297
+ } , [ _c ( 'warp' ) ] , 1 )
298
+ }
299
+ } )
300
+ const app = createInstance ( options )
301
+ app . $mount ( )
302
+
303
+ expect ( onLifecycle ) . toEqual ( [
304
+ 'beforeCreate' ,
305
+ 'created' ,
306
+ 'attached' ,
307
+ 'ready' ,
308
+ 'beforeMount' ,
309
+ 'beforeCreate-warp' ,
310
+ 'created-warp' ,
311
+ 'onLoad-warp' ,
312
+ 'onReady-warp' ,
313
+ 'beforeMount-warp' ,
314
+ 'mounted-warp' ,
315
+ 'mounted'
316
+ ] )
317
+ expect ( ! ! app . $mp . page ) . toEqual ( true )
318
+ expect ( app . $mp . mpType ) . toEqual ( 'component' )
319
+ expect ( app . $mp . status ) . toEqual ( 'ready' )
320
+ } )
321
+
322
+ it ( 'Component with customEvent' , function ( ) {
323
+ const options = Object . assign ( getComponentOptions ( ) , {
324
+ mpType : 'component' ,
325
+ render ( ) {
326
+ var _vm = this
327
+ var _h = _vm . $createElement
328
+ var _c = _vm . _self . _c || _h
329
+ return _c ( 'div' , {
330
+ staticClass : 'container'
331
+ } , [ ] , 1 )
332
+ }
333
+ } )
334
+ const app = createInstance ( options )
335
+ app . $mount ( )
336
+ expect ( onLifecycle ) . toEqual ( [ 'beforeCreate' , 'created' , 'attached' , 'ready' , 'beforeMount' , 'mounted' ] )
337
+ expect ( ! ! app . $mp . page ) . toEqual ( true )
338
+ expect ( app . $mp . mpType ) . toEqual ( 'component' )
339
+ expect ( app . $mp . status ) . toEqual ( 'ready' )
340
+
341
+ // moved
342
+ app . $mp . page . _callHook ( 'moved' )
343
+ expect ( onLifecycle ) . toEqual ( [ 'beforeCreate' , 'created' , 'attached' , 'ready' , 'beforeMount' , 'mounted' , 'moved' ] )
344
+
345
+ // detached
346
+ app . $mp . page . _callHook ( 'detached' )
347
+ expect ( app . $mp . status ) . toEqual ( 'detached' )
348
+ expect ( onLifecycle ) . toEqual ( [ 'beforeCreate' , 'created' , 'attached' , 'ready' , 'beforeMount' , 'mounted' , 'moved' , 'detached' ] )
349
+ } )
240
350
} )
0 commit comments