reactjs – Jest unit test case for graphql mutation’s callbacks methods(onSuccess, onError)

I tried a-lot but facing difficulties to write the unit test case for graphQL mutation’s callbacks, the following is the example code:

const { mutate, isLoading, isSuccess } = useCreateMutation({
    onSuccess: () => {
      refetch();
    }
});

const create = () => {
    mutate({
      createRequest: {
        userId: '12',
      }
    });
};

Anyone can help me to write the unit test case to cover the onSuccess in this scenario, let’s suppose create method is being called on any button from JSX.

It should cover the onSuccess method.

Read more here: Source link