Avoid setImmediate calls on Jest environment #4083
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds Jest specific code to places where we'd used setImmediate. We want to avoid calling setImmediate as it makes writing tests a bit tricky.
The reason is that Jest mocks all the timer-related stuff putting all enqueued function in a single bucket. Then, in order to run these enqueued functions, the test needs to call advanceTimersByTime. It isn't allowed to schedule a callback for the same "tick" which results in the chain of setImmediate calls requiring a several separate runs to advanceTimersByTime. This can be seen in the previous workaround where we had three subsequent calls to that method just in order to start a single animation.
With this change we no longer expect from test to run any additional setup / timer-advancing steps when testing reanimated components and animations.
Test plan
Run jest tests.