withHooks and withoutHooks do not support async tests / promises
See original GitHub issueThanks for this package. I’m currently trying to get this to work with an async test, but that doesn’t seem to be supported yet. Could this be added?
Example usage:
it('does something async', async () => {
await withHooks(async () => {
const wrapper = shallow(<App />);
await something();
});
});
I’m currently using this as a workaround:
export default function withHooksAsync(test: () => Promise<void>): Promise<void> {
return new Promise<void>((resolve, reject) => {
withHooks(() => {
test().then(resolve).catch(reject);
});
});
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:12 (3 by maintainers)
Top Results From Across the Web
For async tests and hooks, ensure "done()" is called
For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. My test code is, I have the...
Read more >A Complete Guide to Testing React Hooks - Toptal
This article explores how to test React Hooks and outlines an eight-step testing plan you could employ to test your own projects.
Read more >Analytics for React Native 2.0 | Segment Documentation
On May 15, 2023, Segment will end support for Analytics React Native Classic, ... See how to use Analytics React Native 2.0 with...
Read more >Hooks are the worst thing to ever happen to React. They're so ...
Most React components that use hooks end up having several chains of promises inside them but no way to await the final promise...
Read more >Using Async Await Inside React's useEffect() Hook
In this post you'll learn how to use an async function inside your React useEffect hook. Perhaps you've been using the good old...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @d-luk ,
Thanks for reporting this. I’ll have a look!
So let’s say you’ve got this component:
This will show the Text “Effected” after three seconds (i sped up the video):
If I use this test-suite: Test Setup
Component.test.tsx
The expected result is that the test succeeds and it’ll wait for the useEffect to run through. Unfortunately, it does not.
Could you have a look at this?