File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -403,6 +403,44 @@ describe("ofetch", () => {
403403 ) . toMatchObject ( { foo : "2" , bar : "3" } ) ;
404404 } ) ;
405405
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+
406444 it ( "calls hooks" , async ( ) => {
407445 const onRequest = vi . fn ( ) ;
408446 const onRequestError = vi . fn ( ) ;
You can’t perform that action at this time.
0 commit comments