@@ -39,7 +39,6 @@ describe('XMLHttpRequest', function() {
39
39
40
40
req . open ( 'get' , '/' , true ) ;
41
41
req . send ( ) ;
42
-
43
42
const lastScheduled = wtfMock . log [ wtfMock . log . length - 1 ] ;
44
43
expect ( lastScheduled ) . toMatch ( '# Zone:schedule:macroTask:XMLHttpRequest.send' ) ;
45
44
} , null , null , 'unit-test' ) ;
@@ -185,27 +184,36 @@ describe('XMLHttpRequest', function() {
185
184
} ) ;
186
185
187
186
it ( 'should work properly when send request multiple times on single xmlRequest instance' ,
188
- function ( ) {
187
+ function ( done ) {
189
188
testZone . run ( function ( ) {
190
189
const req = new XMLHttpRequest ( ) ;
191
190
req . open ( 'get' , '/' , true ) ;
192
191
req . send ( ) ;
193
192
req . onloadend = function ( ) {
193
+ req . onloadend = null ;
194
194
req . open ( 'get' , '/' , true ) ;
195
- req . send ( ) ;
195
+ req . onloadend = function ( ) {
196
+ done ( ) ;
197
+ } ;
198
+ expect ( ( ) => {
199
+ req . send ( ) ;
200
+ } ) . not . toThrow ( ) ;
196
201
} ;
197
202
} ) ;
198
203
} ) ;
199
204
200
205
it ( 'should keep taskcount correctly when abort was called multiple times before request is done' ,
201
- function ( ) {
206
+ function ( done ) {
202
207
testZone . run ( function ( ) {
203
208
const req = new XMLHttpRequest ( ) ;
204
209
req . open ( 'get' , '/' , true ) ;
205
210
req . send ( ) ;
206
211
req . addEventListener ( 'readystatechange' , function ( ev ) {
207
212
if ( req . readyState >= 2 ) {
208
- req . abort ( ) ;
213
+ expect ( ( ) => {
214
+ req . abort ( ) ;
215
+ } ) . not . toThrow ( ) ;
216
+ done ( ) ;
209
217
}
210
218
} ) ;
211
219
} ) ;
@@ -221,4 +229,23 @@ describe('XMLHttpRequest', function() {
221
229
} ;
222
230
expect ( func ) . not . toThrow ( ) ;
223
231
} ) ;
232
+
233
+ it ( 'should be in the zone when use XMLHttpRequest.addEventListener' , function ( done ) {
234
+ testZone . run ( function ( ) {
235
+ // sometimes this case will cause timeout
236
+ // so we set it longer
237
+ const interval = ( < any > jasmine ) . DEFAULT_TIMEOUT_INTERVAL ;
238
+ ( < any > jasmine ) . DEFAULT_TIMEOUT_INTERVAL = 5000 ;
239
+ const req = new XMLHttpRequest ( ) ;
240
+ req . open ( 'get' , '/' , true ) ;
241
+ req . addEventListener ( 'readystatechange' , function ( ) {
242
+ if ( req . readyState === 4 ) {
243
+ // expect(Zone.current.name).toEqual('test');
244
+ ( < any > jasmine ) . DEFAULT_TIMEOUT_INTERVAL = interval ;
245
+ done ( ) ;
246
+ }
247
+ } ) ;
248
+ req . send ( ) ;
249
+ } ) ;
250
+ } ) ;
224
251
} ) ;
0 commit comments