Allow sinon.useFakeTimers() to modify setTimeout() and clearTimeout() after module loads#45
Merged
sindresorhus merged 2 commits intosindresorhus:masterfrom Jun 12, 2019
Merged
Conversation
If `setTimeout` and `clearTimeout` aren't explicitly set in the `createDelay()` call, bind their values when the promise is created. This allows `sinon.useFakeTimers()` to work while still allowing other implementations of those functions to be passed to `createDelay()`. Previously the default `setTimeout` and `clearTimeout` were set aside when the module was loaded, meaning default `delay` and `delay.reject` didn't notice if they were later stubbed out.
index.js
Outdated
| let timeoutId; | ||
| let settle; | ||
| let rejectFn; | ||
| const c = clear || clearTimeout; |
Owner
There was a problem hiding this comment.
Needs a more descriptive variable name than c.
Owner
|
The PR title should describe what it fixes, not what it contains. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
If
setTimeoutandclearTimeoutaren't explicitly set in thecreateDelay()call, bind their values when the promise is created. This allowssinon.useFakeTimers()to work while still allowing other implementations of those functions to be passed tocreateDelay(). Previously the defaultsetTimeoutandclearTimeoutwere set aside when the module was loaded, meaning defaultdelayanddelay.rejectdidn't notice if they were later stubbed out.Resolves the issue I raised in the comments for #39.