Skip to content

Commit

Permalink
test: add additional tests for hook errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 28, 2024
1 parent 180e415 commit 7ff4d11
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,44 @@ describe("ofetch", () => {
).toMatchObject({ foo: "2", bar: "3" });
});

it("hook errors", async () => {
// onRequest
await expect(
$fetch(getURL("/ok"), {
onRequest: () => {
throw new Error("error in onRequest");
},
})
).rejects.toThrow("error in onRequest");

// onRequestError
await expect(
$fetch("/" /* non absolute is not acceptable */, {
onRequestError: () => {
throw new Error("error in onRequestError");
},
})
).rejects.toThrow("error in onRequestError");

// onResponse
await expect(
$fetch(getURL("/ok"), {
onRequest: () => {
throw new Error("error in onResponse");
},
})
).rejects.toThrow("error in onResponse");

// onResponseError
await expect(
$fetch(getURL("/403"), {
onResponseError: () => {
throw new Error("error in onResponseError");
},
})
).rejects.toThrow("error in onResponseError");
});

it("calls hooks", async () => {
const onRequest = vi.fn();
const onRequestError = vi.fn();
Expand Down

0 comments on commit 7ff4d11

Please sign in to comment.