@@ -39,7 +39,6 @@ describe('XMLHttpRequest', function() {
3939
4040 req . open ( 'get' , '/' , true ) ;
4141 req . send ( ) ;
42-
4342 const lastScheduled = wtfMock . log [ wtfMock . log . length - 1 ] ;
4443 expect ( lastScheduled ) . toMatch ( '# Zone:schedule:macroTask:XMLHttpRequest.send' ) ;
4544 } , null , null , 'unit-test' ) ;
@@ -185,27 +184,36 @@ describe('XMLHttpRequest', function() {
185184 } ) ;
186185
187186 it ( 'should work properly when send request multiple times on single xmlRequest instance' ,
188- function ( ) {
187+ function ( done ) {
189188 testZone . run ( function ( ) {
190189 const req = new XMLHttpRequest ( ) ;
191190 req . open ( 'get' , '/' , true ) ;
192191 req . send ( ) ;
193192 req . onloadend = function ( ) {
193+ req . onloadend = null ;
194194 req . open ( 'get' , '/' , true ) ;
195- req . send ( ) ;
195+ req . onloadend = function ( ) {
196+ done ( ) ;
197+ } ;
198+ expect ( ( ) => {
199+ req . send ( ) ;
200+ } ) . not . toThrow ( ) ;
196201 } ;
197202 } ) ;
198203 } ) ;
199204
200205 it ( 'should keep taskcount correctly when abort was called multiple times before request is done' ,
201- function ( ) {
206+ function ( done ) {
202207 testZone . run ( function ( ) {
203208 const req = new XMLHttpRequest ( ) ;
204209 req . open ( 'get' , '/' , true ) ;
205210 req . send ( ) ;
206211 req . addEventListener ( 'readystatechange' , function ( ev ) {
207212 if ( req . readyState >= 2 ) {
208- req . abort ( ) ;
213+ expect ( ( ) => {
214+ req . abort ( ) ;
215+ } ) . not . toThrow ( ) ;
216+ done ( ) ;
209217 }
210218 } ) ;
211219 } ) ;
@@ -221,4 +229,23 @@ describe('XMLHttpRequest', function() {
221229 } ;
222230 expect ( func ) . not . toThrow ( ) ;
223231 } ) ;
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+ } ) ;
224251} ) ;
0 commit comments