Skip to content

Commit cff269d

Browse files
committed
test: add test reproducing usemutation type error
1 parent 12f9c29 commit cff269d

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

packages/openapi-react-query/test/index.test.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,42 @@ describe("client", () => {
792792

793793
await waitFor(() => rendered.findByText("data: Hello, status: success"));
794794
});
795+
796+
it("should resolve mutation options properly for onError and onSettled", async () => {
797+
const fetchClient = createFetchClient<paths>({ baseUrl });
798+
const client = createClient(fetchClient);
799+
800+
useMockRequestHandler({
801+
baseUrl,
802+
method: "put",
803+
path: "/comment",
804+
status: 200,
805+
body: undefined,
806+
});
807+
808+
const { result } = renderHook(() => client.useMutation("put", "/comment",
809+
{
810+
onMutate: () => {
811+
const someArray = [1,2,3]
812+
const someString = "abc"
813+
return { someArray, someString }
814+
},
815+
onError: (err, _, onMutateResult, context) => {
816+
if (onMutateResult) {
817+
console.log(onMutateResult.someArray)
818+
console.log(onMutateResult.someString)
819+
}
820+
},
821+
// Always refetch after error or success:
822+
onSettled: (_data, _error, _variables, onMutateResult, context) => {
823+
if (onMutateResult) {
824+
console.log(onMutateResult.someArray)
825+
console.log(onMutateResult.someString)
826+
}
827+
}
828+
}
829+
), { wrapper });
830+
});
795831
});
796832

797833
describe("mutateAsync", () => {

0 commit comments

Comments
 (0)