Skip to content

Commit 7ff4d11

Browse files
committedAug 28, 2024·
test: add additional tests for hook errors
1 parent 180e415 commit 7ff4d11

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
 

‎test/index.test.ts

+38
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)
Please sign in to comment.