@@ -17,23 +17,34 @@ describe('XMLHttpRequest', function() {
1717
1818 it ( 'should intercept XHRs and treat them as MacroTasks' , function ( done ) {
1919 let req : XMLHttpRequest ;
20- const testZoneWithWtf =
21- Zone . current . fork ( ( Zone as any ) [ 'wtfZoneSpec' ] ) . fork ( { name : 'TestZone' } ) ;
20+ let onStable : any ;
21+ const testZoneWithWtf = Zone . current . fork ( ( Zone as any ) [ 'wtfZoneSpec' ] ) . fork ( {
22+ name : 'TestZone' ,
23+ onHasTask : ( delegate : ZoneDelegate , curr : Zone , target : Zone , hasTask : HasTaskState ) => {
24+ if ( ! hasTask . macroTask ) {
25+ onStable && onStable ( ) ;
26+ }
27+ }
28+ } ) ;
2229
2330 testZoneWithWtf . run ( ( ) => {
2431 req = new XMLHttpRequest ( ) ;
32+ const logs : string [ ] = [ ] ;
2533 req . onload = ( ) => {
26- // The last entry in the log should be the invocation for the current onload,
27- // which will vary depending on browser environment. The prior entries
28- // should be the invocation of the send macrotask.
29- expect ( wtfMock . log [ wtfMock . log . length - 3 ] )
30- . toEqual ( '> Zone:invokeTask:XMLHttpRequest.send("<root>::ProxyZone::WTF::TestZone")' ) ;
34+ logs . push ( 'onload' ) ;
35+ } ;
36+ onStable = function ( ) {
3137 expect ( wtfMock . log [ wtfMock . log . length - 2 ] )
38+ . toEqual ( '> Zone:invokeTask:XMLHttpRequest.send("<root>::ProxyZone::WTF::TestZone")' ) ;
39+ expect ( wtfMock . log [ wtfMock . log . length - 1 ] )
3240 . toEqual ( '< Zone:invokeTask:XMLHttpRequest.send' ) ;
3341 if ( supportPatchXHROnProperty ( ) ) {
34- expect ( wtfMock . log [ wtfMock . log . length - 1 ] )
42+ expect ( wtfMock . log [ wtfMock . log . length - 3 ] )
43+ . toMatch ( / \< Z o n e \: i n v o k e T a s k .* a d d E v e n t L i s t e n e r \: l o a d / ) ;
44+ expect ( wtfMock . log [ wtfMock . log . length - 4 ] )
3545 . toMatch ( / \> Z o n e \: i n v o k e T a s k .* a d d E v e n t L i s t e n e r \: l o a d / ) ;
3646 }
47+ expect ( logs ) . toEqual ( [ 'onload' ] ) ;
3748 done ( ) ;
3849 } ;
3950
0 commit comments