Skip to content
This repository has been archived by the owner on Nov 11, 2023. It is now read-only.

Commit

Permalink
fix: Avoid including undefined bodies in DELETE
Browse files Browse the repository at this point in the history
  • Loading branch information
torkelrogstad authored and fabien0102 committed Dec 11, 2020
1 parent 01b145b commit d7e7648
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/useMutate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,26 @@ describe("useMutate", () => {
expect(res).toEqual({ id: 1 });
});

it("should deal with undefined bodies", async () => {
nock("https://my-awesome-api.fake")
.delete("/")
.reply(200, { id: 1 });

const wrapper: React.FC = ({ children }) => (
<RestfulProvider base="https://my-awesome-api.fake">{children}</RestfulProvider>
);
const { result } = renderHook(() => useMutate<any, any, { [key: string]: any }, void, void>("DELETE", ""), {
wrapper,
});
const res = await result.current.mutate();

expect(result.current).toMatchObject({
error: null,
loading: false,
});
expect(res).toEqual({ id: 1 });
});

it("should deal with query parameters", async () => {
nock("https://my-awesome-api.fake")
.delete("/")
Expand Down
2 changes: 1 addition & 1 deletion src/useMutate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export function useMutate<
options.body = body;
} else if (typeof body === "object") {
options.body = JSON.stringify(body);
} else if (isDelete) {
} else if (isDelete && body !== undefined) {
const possiblyEncodedBody = props.pathInlineBodyEncode
? props.pathInlineBodyEncode(String(body))
: String(body);
Expand Down

0 comments on commit d7e7648

Please sign in to comment.