Issue #1852: Add a way to pass a global context to lolex when calling useFakeTimers #1935
+23
−3
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.
Purpose (TL;DR)
Partial fix of issue #1852: Add a way to pass a global context to lolex when calling useFakeTimers
Background
As discussed in #1852, some environments make
sinon.useFakeTimers
crash, because oflolex
, when some properties are missing in theglobal
object. The issue has been improved by triggering a more explicit error inlolex
, however this PR adds a way to provide the global context directly and forward it tololex
.Solution
This PR adds an extra property when using
sinon.useFakeTimers
with an object argument: by giving theglobal
property,lolex.withGlobal(global)
will be called and used to install the clock instead of using the default implementation.How to verify
Checkout this repositoy for an example of an environment that triggers this bug.