Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing Mutation - Waiting for Mutation to Complete #6452

Closed
sgentile opened this issue Jun 17, 2020 · 4 comments
Closed

Testing Mutation - Waiting for Mutation to Complete #6452

sgentile opened this issue Jun 17, 2020 · 4 comments

Comments

@sgentile
Copy link

The documentation shows this line of code

await wait(0);

This throws an error:

TypeError: callback is not a function

What is the proper way to wait for a mutation to complete in a react library test/jest scenario ?

@dylanwulf
Copy link
Contributor

dylanwulf commented Jun 17, 2020

The point of await wait() is just to wait for the next iteration of the event loop so that the promise can resolve. This should work just as well:

await new Promise(resolve => setTimeout(resolve, 0));

Or if you're using @testing-library/react you can do this instead:

await act(async () => {
    // perform some action that would cause the mutation to fire
});

Hope this helps!

@sgentile
Copy link
Author

I was able to get past this. My issue now is on queries. I see the loading go from true to false however I get null data and no errors.

Unlike a mutation I do not see what could help in terms of validation it's called - the code is using a useQuery

@WojciechMatuszewski
Copy link

WojciechMatuszewski commented Jun 29, 2020

I was able to get past this. My issue now is on queries. I see the loading go from true to false however I get null data and no errors.

Unlike a mutation I do not see what could help in terms of validation it's called - the code is using a useQuery

Is you query using the cache-only fetch policy?

@sgentile
Copy link
Author

sgentile commented Jul 6, 2020

I'm not setting that specifically anywhere ?

@hwillson hwillson closed this as completed May 3, 2021
@apollographql apollographql locked and limited conversation to collaborators May 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants