inturn/react-recoil-hooks-testing-library

State initializers do not fire until after hooks under test begin executing

Opened this issue · 0 comments

It appears the codebase does something like

<RecoilRoot>
{components that initialize recoil state}
{children involved in testing custom hook}
</RecoilRoot>

This will result in children potentially, but not always, trying to get recoil state before the components that initialize recoil state have "initialized" recoil state (they actually set a previously-initialized Recoil state; they don't initialize it). Many tests will fail purely because of this race condition.

RecoilRoot has an optional prop that does true state initialization: initializeState?: ({set, setUnvalidatedAtomValues}) => void. This should be used because it will avoid race conditions.