@@ -286,7 +286,7 @@ describe('response negotiation', () => {
286
286
) ;
287
287
} ) ;
288
288
289
- it ( 'aborts sending request options body stream' , async ( ) => {
289
+ it ( 'aborts sending when a body stream is provided as a request option ' , async ( ) => {
290
290
fm . route ( '*' , 200 , { delay : 50 } ) ;
291
291
const body = new ReadableStream ( ) ;
292
292
vi . spyOn ( body , 'cancel' ) ;
@@ -304,7 +304,7 @@ describe('response negotiation', () => {
304
304
) ;
305
305
} ) ;
306
306
307
- // this doesn't work as the callLog creatde from the request awaits the body
307
+ // this doesn't work as the callLog created from the request awaits the body
308
308
it . skip ( 'aborts sending request body stream' , async ( ) => {
309
309
fm . route ( '*' , 200 , { delay : 50 } ) ;
310
310
const body = new ReadableStream ( ) ;
@@ -323,9 +323,42 @@ describe('response negotiation', () => {
323
323
) ;
324
324
} ) ;
325
325
326
- it . skip ( 'aborts receiving response body stream' , async ( ) => {
327
- // so fiddly to implement a test for this. Uses the same mechanism as cancelling request body though
328
- // so I trust that if one works the other does
326
+ it . skip ( 'aborts receiving body stream response' , async ( ) => {
327
+ const controller = new AbortController ( ) ;
328
+
329
+ const body = new ReadableStream ( ) ;
330
+ vi . spyOn ( body , 'cancel' ) ;
331
+ fm . route ( '*' , body ) ;
332
+ const res = await fm . fetchHandler ( 'http://a.com' , {
333
+ signal : controller . signal ,
334
+ } ) ;
335
+ controller . abort ( ) ;
336
+ await expect ( res . bytes ( ) ) . rejects . toThrowError (
337
+ new DOMException ( 'The operation was aborted.' , 'AbortError' ) ,
338
+ ) ;
339
+
340
+ expect ( body . cancel ) . toHaveBeenCalledWith (
341
+ new DOMException ( 'The operation was aborted.' , 'AbortError' ) ,
342
+ ) ;
343
+ } ) ;
344
+
345
+ it . skip ( 'aborts receiving body stream response when in middle of reading stream' , async ( ) => {
346
+ const controller = new AbortController ( ) ;
347
+
348
+ const body = new ReadableStream ( ) ;
349
+ vi . spyOn ( body , 'cancel' ) ;
350
+ fm . route ( '*' , body ) ;
351
+ const res = await fm . fetchHandler ( 'http://a.com' , {
352
+ signal : controller . signal ,
353
+ } ) ;
354
+ const bodyPromise = res . bytes ( ) ;
355
+ controller . abort ( ) ;
356
+ await expect ( bodyPromise ) . rejects . toThrowError (
357
+ new DOMException ( 'The operation was aborted.' , 'AbortError' ) ,
358
+ ) ;
359
+ expect ( body . cancel ) . toHaveBeenCalledWith (
360
+ new DOMException ( 'The operation was aborted.' , 'AbortError' ) ,
361
+ ) ;
329
362
} ) ;
330
363
331
364
it ( 'go into `done` state even when aborted' , async ( ) => {
0 commit comments