Skip to content

Commit

Permalink
test(axios): add test case for status code validation
Browse files Browse the repository at this point in the history
  • Loading branch information
orionmiz committed Aug 26, 2024
1 parent 6ada809 commit a1966ba
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/plantae/src/axios/createAxiosInterceptors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,4 +558,30 @@ describe("createAxiosInterceptors", () => {
modified: true,
});
});

it("should throw error if status code validation failed", async () => {
server.use(
http.get(base("/"), () => {
return new Response(null, {
status: 500,
});
})
);

const axios = Axios.create({
baseURL,
});

const { request, response } = createAxiosInterceptors({
client: axios,
plugins: [],
});

axios.interceptors.request.use(request.onFulfilled, request.onRejected);
axios.interceptors.response.use(response.onFulfilled, response.onRejected);

await expect(axios.get("/")).rejects.toThrow(
"Request failed with status code 500"
);
});
});

0 comments on commit a1966ba

Please sign in to comment.