Skip to content

Commit e74dce4

Browse files
committed
test(axios): add test spec
1 parent 7bb7789 commit e74dce4

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

packages/plantae/src/axios/createAxiosInterceptors.spec.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,4 +584,50 @@ describe("createAxiosInterceptors", () => {
584584
"Request failed with status code 500",
585585
);
586586
});
587+
588+
it.only("should not throw error if form data body is reused", async () => {
589+
let retried = false;
590+
591+
server.use(
592+
http.post(base("/"), () => {
593+
return new Response(retried ? Status.OK : Status.BAD, {
594+
status: retried ? 200 : 500,
595+
});
596+
}),
597+
);
598+
599+
const axios = Axios.create({
600+
baseURL,
601+
});
602+
603+
const { request, response } = createAxiosInterceptors({
604+
client: axios,
605+
plugins: [
606+
{
607+
name: "plugin-modify-body",
608+
hooks: {
609+
afterResponse: (res, req, retry) => {
610+
if (res.status === 500) {
611+
retried = true;
612+
613+
return retry(req);
614+
}
615+
return res;
616+
},
617+
},
618+
},
619+
],
620+
});
621+
622+
axios.interceptors.request.use(request.onFulfilled, request.onRejected);
623+
axios.interceptors.response.use(response.onFulfilled, response.onRejected);
624+
625+
const formData = new FormData();
626+
627+
formData.append("foo", "bar");
628+
629+
const res = await axios.post("/", formData);
630+
631+
expect(res.data).toBe(Status.OK);
632+
});
587633
});

0 commit comments

Comments
 (0)