-
Notifications
You must be signed in to change notification settings - Fork 232
Having issues using useEffect - Async callback was not invoked ... #313
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
Comments
The "Async callback" that error is referring to is the If you're using a relatively new version of jest (possibly any version, but I'm not sure if it's always been this way), you can omit the describe("useEntity Testing Custom Hook", () => {
test("useEntity performs GET request", async () => {
const mock = new mockAdapter(axios);
const mockData = "response";
const url = "http://mock";
mock.onGet(url).reply(200, mockData);
const { result, waitForNextUpdate } = renderHook(() =>
useEntity("70695957658")
);
expect(result.current.results).toEqual([]);
expect(result.current.loading).toBeTruthy();
await waitForNextUpdate();
expect(result.current.results).toEqual([]);
expect(result.current.loading).toBeTruthy();
});
}); The way, the |
Hi @mpeyper . Thanks for your prompt response. I did the changes that you suggested to me, but I still have the same problem: I'm using:
|
What version of |
Hi @mpeyper , I'm using: "react": "^16.8.0", Do you have any ideas why this doesn't work ?. Thanks. |
I've seen cases where tests silently fail when The other thing I notice is that both Other than that, all I can think is that the way the test is failing is presenting itself as a timeout, rather than something actually being wrong. If it helps I was able to get a green test using later versions and making some grand assumptions on what the functionality is meant to be doing. You can see the test passing in this sandbox. |
Hi @mpeyper . Thanks for your prompt response. This is my output:
I have updated my versions of Do you have any other new ideas about this behavior?. Thanks. |
No, I'm afraid I'm out of ideas. I suspect the issue will turn out to be something preventing the hook from running as expected (an error, for example) and the state is never updating, preventing Have you looked at my sandbox yet? I was able to get a passing test with a few adjustments to the test setup. |
I've just started to wonder if this issue might be related to #308 somehow? If the error is being thrown in the effect (most likely in this case), then the current error handling won't catch it to resolve and waits either. |
What is your question:
I'm trying to test my custom hook, but I can't pass it because I receive the following error:
Relevant code or config:
https://gist.github.com/rodrigo398/e50381a3bdb38dabcc8452e9c17d8992
Can someone suggest ideas ? Thank you for your help!.
The text was updated successfully, but these errors were encountered: