birdofpreyru / react-utils

ReactJS development kit.
https://dr.pogodin.studio/docs/react-utils/index.html
Other
3 stars 0 forks source link

`snapshot()` improvements #345

Open birdofpreyru opened 1 month ago

birdofpreyru commented 1 month ago

(See __tests__/shared/routes/index.tsx in react-starter, which uses snapshot() and gets a warning from React about act() missing).

https://github.com/birdofpreyru/react-utils/blob/a137781e93905865100a95dee1aa7a447d845d56/src/shared/utils/jest/index.tsx#L104

also perhaps we need an option to automatically add client side initialization (wrapping provided component with the global state and router providers)

birdofpreyru commented 1 month ago

Does not seem to solve the problem.

birdofpreyru commented 1 month ago

Perhaps, the problem in that test is that it snapshots a component tree with an async split chunk in it, thus no matter act() or not in the snapshot() method, if we don't wait specifically for split component pending promise, it has no effect?

Perhaps revert changes done in af2e6fb?

birdofpreyru commented 1 month ago

Agh... I guess, the actual solution here is to have a second, optional argument to the snapshot() — snapshot options; and if we need to do async act() waiting for something before considering the render completed, pass a promise to wait as an option there, take it if present wait for it.

And then the problematic tests in react-starter has to be correctly wrapped into the frontend RU app init logic (it needs global state provider, router, etc.), but that is a different problem.

birdofpreyru commented 6 days ago

Done, but it is to be verified if the update solves the root problem.