Jest runs and finishes when expected.
After adding an <Observer> to a component and using that component in a test with Jest and react-test-renderer, Jest runs successfully but returns a warning Jest did not exit one second after the test run has completed.
Repo using expo-init and the basic tabs example
clone, yarn, jest
Thanks for the report. The problem is kinda obvious ...
It's a crutch timer that should take care of lingering reactions, but nobody takes care of that lingering timer ๐. In the normal app, it's not a problem because it needs to run all the time and it's ended with app exit.
However, fix is much trickier as we can't exactly detect when the timer is not needed anymore. Reference counting of "live" observers sounds like a dangerous approach too.
The "dirty" solution would be to basically expose the script with afterAll that would clean that timer.
I am open to other suggestions ... @RoystonS @xaviergonz @mweststrate @urugator
Hello, @FredyC .
I'm facing the same problem. Do you have any update about that?
@alanhr Not really, if you read my last comment, there is no clear path on how to proceed here. React is not giving proper tools for handling this.
Hmm, it would be interesting to see how recoil or relay handle this, I'm
pretty sure they have a similar clean up strategy.
On Mon, Jun 29, 2020 at 2:00 PM Daniel K. notifications@github.com wrote:
@alanhr https://github.com/alanhr Not really, if you read my last
comment, there is no clear path on how to proceed here. React is not giving
proper tools for handling this.โ
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/mobxjs/mobx-react-lite/issues/288#issuecomment-651104020,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAN4NBGKVW7EKT7QCPQGYTTRZCF6FANCNFSM4NEPLZTQ
.
jest.useFakeTimers() is solving the problem.
@liamkernighan this was my solution to solve that problem
@liamkernighan It's cool, but it's more like a workaround. Faking timers can have unforeseen consequences. It's easy to forget about it and then be surprised why is test stuck.
It would be straightforward to expose a 'debug-only' call (for unit-testing use only) that shuts down the timer, and call that from the Jest (or other unit test framework) teardown.
Anyone feel free to PR a clearTimers utility.
P.S. I noticed that in the above example the test example the render tree is never cleaned up, so doing that might help as well.
I'll do this within the next few days.
There's already a resetCleanupScheduleForTests() which mobx-react-lite's own tests use to clean the timers up. I'll just expose that as clearTimers().
Most helpful comment
It would be straightforward to expose a 'debug-only' call (for unit-testing use only) that shuts down the timer, and call that from the Jest (or other unit test framework) teardown.