Skip to content

Commit f2ca453

Browse files
committed
test: fix mutation onSuccess assertion to handle varying React Query callback signatures
React Query's onSuccess callback signature varies between versions. Instead of asserting exact call arguments, now verify only the first two arguments (data and variables) using mock.calls to be version-agnostic.
1 parent bfdcc57 commit f2ca453

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -815,12 +815,11 @@ describe("client", () => {
815815
result.current.mutate({ body: { message: "Test", replied_at: 123456789 } });
816816

817817
await waitFor(() => expect(result.current.isSuccess).toBe(true));
818-
expect(onSuccessSpy).toHaveBeenNthCalledWith(
819-
1,
820-
{ message: "Success" },
821-
{ body: { message: "Test", replied_at: 123456789 } },
822-
undefined,
823-
);
818+
// Verify onSuccess was called with correct data and variables
819+
expect(onSuccessSpy).toHaveBeenCalledTimes(1);
820+
const [data, variables] = onSuccessSpy.mock.calls[0];
821+
expect(data).toEqual({ message: "Success" });
822+
expect(variables).toEqual({ body: { message: "Test", replied_at: 123456789 } });
824823
// Verify that mutationKey is part of the options object
825824
expect(options).toEqual(expect.objectContaining({ mutationKey: ["put", "/comment"] }));
826825
expect(onErrorSpy).not.toHaveBeenCalled();

0 commit comments

Comments
 (0)