Replies: 2 comments 2 replies
-
Async atoms suspend the react component that consumes them. You can try adding Suspense to your wrapper. |
Beta Was this translation helpful? Give feedback.
2 replies
-
You are using react test utils to test the jotai. but jotai atoms could be ran without react component. from my practice, I would like to use |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm confused about how to test async atom computation. I have a set of atoms:-
There is no async behaviour in the
derivedAtom
other than waiting for thethingAtom
to resolve. In the product code,thingAtom
is set by fetching something based onthingIdAtom
, but in my test, I'm setting it to a mocked Thing (no Promise) withuseHydrateAtoms
. When I usethen
result.current
is null. If I wrap the renderHook call in await act(...), or I use waitForNextRender, the test times out.What's the right way (or any working way) to unit-test atom derivations when there is async behaviour? This behaviour of async atoms appearing null on first render, even though the return type doesn't include null, does seem very error-prone.
Beta Was this translation helpful? Give feedback.
All reactions