@@ -47,3 +47,43 @@ describe('global function patch', () => {
47
47
} ) ) ;
48
48
} ) ;
49
49
} ) ;
50
+
51
+ describe ( 'ZoneTask' , ( ) => {
52
+ it ( 'should return handleId.toString if handleId is available' , ( ) => {
53
+ let macroTask1 : any = undefined ;
54
+ let macroTask2 : any = undefined ;
55
+ let microTask : any = undefined ;
56
+ const zone = Zone . current . fork ( {
57
+ name : 'timer' ,
58
+ onScheduleTask : ( delegate : ZoneDelegate , curr : Zone , target : Zone , task : Task ) => {
59
+ if ( task . type === 'macroTask' ) {
60
+ if ( ! macroTask1 ) {
61
+ macroTask1 = task ;
62
+ } else {
63
+ macroTask2 = task ;
64
+ }
65
+ } else if ( task . type === 'microTask' ) {
66
+ microTask = task ;
67
+ }
68
+ return task ;
69
+ }
70
+ } ) ;
71
+ zone . run ( ( ) => {
72
+ const id1 = setTimeout ( ( ) => { } ) ;
73
+ clearTimeout ( id1 ) ;
74
+ const id2 = setTimeout ( ( ) => { } ) ;
75
+ clearTimeout ( id2 ) ;
76
+ Promise . resolve ( ) . then ( ( ) => { } ) ;
77
+ const macroTask1Str = macroTask1 . toString ( ) ;
78
+ const macroTask2Str = macroTask2 . toString ( ) ;
79
+ expect ( typeof macroTask1Str ) . toEqual ( 'string' ) ;
80
+ expect ( macroTask1Str ) . toEqual ( id1 . toString ( ) ) ;
81
+ expect ( typeof macroTask2Str ) . toEqual ( 'string' ) ;
82
+ expect ( macroTask2Str ) . toEqual ( id2 . toString ( ) ) ;
83
+ if ( macroTask1 . data && typeof macroTask1 . data . handleId === 'number' ) {
84
+ expect ( macroTask1Str ) . not . toEqual ( macroTask2Str ) ;
85
+ }
86
+ expect ( typeof microTask . toString ( ) ) . toEqual ( 'string' ) ;
87
+ } ) ;
88
+ } ) ;
89
+ } ) ;
0 commit comments