@@ -17,23 +17,34 @@ describe('XMLHttpRequest', function() {
17
17
18
18
it ( 'should intercept XHRs and treat them as MacroTasks' , function ( done ) {
19
19
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
+ } ) ;
22
29
23
30
testZoneWithWtf . run ( ( ) => {
24
31
req = new XMLHttpRequest ( ) ;
32
+ const logs : string [ ] = [ ] ;
25
33
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 ( ) {
31
37
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 ] )
32
40
. toEqual ( '< Zone:invokeTask:XMLHttpRequest.send' ) ;
33
41
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 ] )
35
45
. 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 / ) ;
36
46
}
47
+ expect ( logs ) . toEqual ( [ 'onload' ] ) ;
37
48
done ( ) ;
38
49
} ;
39
50
0 commit comments