Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fake timers in test to avoid unreliable test behavior #1

Closed
wants to merge 1 commit into from

Conversation

avegancafe
Copy link

@avegancafe avegancafe commented May 27, 2020

Not sure why specifically this is happening, but making this render use fake timers when running effects removes the nondeterminism from this test. I think now this test can also remove the promise flushing, since the effects are invoked and the timeout is executed with the act-- not absolutely positive on this one, but I ran it a ton of times and it never failed. This test also still works if the flushing of promises is kept in there too, so no harm done with it if it's necessary for some other reason.

Hope this helps! I pretty much always use fake timers whenever I have any set(Timeout|Interval) stuff going on and I've had good luck avoiding stuff like this. I'm not 100% sure if jest still isn't cleaning things up completely, but hopefully, it should be able to reset its own state of useFakeTimers easier than it can clear all timeouts

Not sure why specifically this is happening, but making this render use
fake timers when running effects removes the nondeterminism from this
test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant