-
I have a component I'm testing that does a mutation, optimistically updates and then refetches the query when settled. The test for it passes, but we get several act warnings and an error from I essentially have a mutation like the below and I hit the error block in the const { mutate } = useMutation(
async ({ postId, userId }) => {
console.log({ postId, userId });
const res = await fetch(
`https://jsonplaceholder.typicode.com/posts/${postId}`,
{
method: "PUT",
body: JSON.stringify({ userId })
}
);
console.log({ res });
return res.json();
},
{
onMutate: ({ postId, userId }) => {
const previousUserId = userId;
setUser(userId);
return { previousUserId };
},
onSettled: (data, error, vars, { previousUserId }) => {
if (error) {
console.log({ previousUserId });
setUser(previousUserId);
console.error({ error });
}
queryClient.refetchQueries(["posts"], { active: true, exact: true });
}
}
); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I actually think I figured this out. Sharing a queryClient in our tests. Even with clearing it before or after each, errors. But if I have each test it's own client, then all the errors went away. |
Beta Was this translation helpful? Give feedback.
I actually think I figured this out. Sharing a queryClient in our tests. Even with clearing it before or after each, errors. But if I have each test it's own client, then all the errors went away.