-
-
Notifications
You must be signed in to change notification settings - Fork 770
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
"TypeError: Cannot read property 'now' of undefined" when sinon.useFakeTimers() #1852
Comments
Same problem with |
A curious phenomenon. I've tried to replicate this using a vanilla Angular project and Sinon 6.1.0, but useFakeTimers() doesn't throw any errors for me, so it might be something in the project environment itself. From the error message, my guess is this variable becomes undefined somehow. |
@moraveyo do you think you can boil this down to a minimal example that shows the issue? Stack Overflow has a guide on How to create a Minimal, Complete, and Verifiable example |
I don't have much time for that now, sorry. |
@mroderick I just encountered this issue today. Here is a small repository that replicates the issue: here. The bug needs both |
@LouisBrunner thank you for creating a runnable test case that is easy to understand 👍 Running the test with The line that fails is lolex-src.js#L131, just as you concluded with your analysis. As you concluded, the root cause of this is that the
// create a lolex implementation using node's `global`
const lolex = require("lolex").withGlobal(global);
const clock = lolex.install();
setTimeout(fn, 15); // Schedules with clock.setTimeout
clock.uninstall(); We can certainly improve |
@mroderick Glad the example helped! 😃 I'd be happy to create a PR, however that will only fix |
Is there any new updates about get Error: The global scope doesn't have a `Date` object (see https://github.com/sinonjs/sinon/issues/1852#issuecomment-419622780) |
@LouisBrunner I like that that idea, I think that solution would work for most people 👍 |
…calling useFakeTimers
@mroderick I created a PR (#1935) that implement a way to pass the global context through |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This has been fixed with #1935 |
I am using sinon 7.2.7 and when I try to use
|
The same. |
Describe the bug
Using sinon@6.1.0 when I do
sinon.useFakeTimers()
- I got an error:When I downgrade to sinon@5 - everything is allright!
My repo:
https://github.com/moraveyo/chess-clock/blob/bf764f3ed9026366de9375bbc870109e4f007099/tests/unit/Countdown.spec.js#L23
Context (please complete the following information):
The text was updated successfully, but these errors were encountered: