File tree 1 file changed +38
-0
lines changed
1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -403,6 +403,44 @@ describe("ofetch", () => {
403
403
) . toMatchObject ( { foo : "2" , bar : "3" } ) ;
404
404
} ) ;
405
405
406
+ it ( "hook errors" , async ( ) => {
407
+ // onRequest
408
+ await expect (
409
+ $fetch ( getURL ( "/ok" ) , {
410
+ onRequest : ( ) => {
411
+ throw new Error ( "error in onRequest" ) ;
412
+ } ,
413
+ } )
414
+ ) . rejects . toThrow ( "error in onRequest" ) ;
415
+
416
+ // onRequestError
417
+ await expect (
418
+ $fetch ( "/" /* non absolute is not acceptable */ , {
419
+ onRequestError : ( ) => {
420
+ throw new Error ( "error in onRequestError" ) ;
421
+ } ,
422
+ } )
423
+ ) . rejects . toThrow ( "error in onRequestError" ) ;
424
+
425
+ // onResponse
426
+ await expect (
427
+ $fetch ( getURL ( "/ok" ) , {
428
+ onRequest : ( ) => {
429
+ throw new Error ( "error in onResponse" ) ;
430
+ } ,
431
+ } )
432
+ ) . rejects . toThrow ( "error in onResponse" ) ;
433
+
434
+ // onResponseError
435
+ await expect (
436
+ $fetch ( getURL ( "/403" ) , {
437
+ onResponseError : ( ) => {
438
+ throw new Error ( "error in onResponseError" ) ;
439
+ } ,
440
+ } )
441
+ ) . rejects . toThrow ( "error in onResponseError" ) ;
442
+ } ) ;
443
+
406
444
it ( "calls hooks" , async ( ) => {
407
445
const onRequest = vi . fn ( ) ;
408
446
const onRequestError = vi . fn ( ) ;
You can’t perform that action at this time.
0 commit comments