-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[RNMobile] Mock Date.now
when using Jest's fake timers to allow debounce
to be executed
#50784
Conversation
4df2773
to
51ea959
Compare
51ea959
to
e418386
Compare
Size Change: 0 B Total Size: 1.4 MB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks so much for identifying this issue and working on the fix, @fluiddot! It works perfectly for me. 👏 🙇♀️
Flaky tests detected in f592b14. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5026453837
|
What?
Mock
Date.now
when using Jest's fake timers to allowdebounce
to be executed.Why?
In integration tests, if a component uses the
debounce
function, the debounced function never gets triggered. This PR solves this issue.How?
debounce
relies on the time returned byDate.now
to calculate the expiration of the timer:gutenberg/packages/compose/src/utils/debounce/index.ts
Lines 192 to 200 in ce29b86
However,
Date.now
is returning the real-time even when using fake timers. To avoid this,Date.now
is mocked when using thewithFakeTimers
test helper that enables/disables the fake timers.Testing Instructions
npm run native test
.Testing Instructions for Keyboard
N/A
Screenshots or screencast
N/A