Skip to content
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

install() throws if setImmediate/clearImmediate is set in config.toFake if _global.setImmediate does not exist #277

Closed
SanderDeWaal1992 opened this issue Nov 26, 2019 · 3 comments

Comments

@SanderDeWaal1992
Copy link

SanderDeWaal1992 commented Nov 26, 2019

  • Lolex version : 5.1.1
  • Environment : Chrome

What did you expect to happen?

That 'setImmediate' and 'clearImmediate' would be ignored if you pass them to config.toFake if _global.setImmediate does not exist since there is nothing to fake for them.

What actually happens

It works in node, but it does not work in Chrome (were setImmediate is not available). In that case it throws:

TypeError: Cannot set property 'hadOwnProperty' of undefined
            at hijackMethod (.../lolex.js:529:1)
            at Object.install (.../lolex.js:1265:1)

How to reproduce

lolex.install({ now: 0, toFake: [
            "setImmediate", "clearImmediate",
            /** and others: */
            "setTimeout", "clearTimeout", "setInterval", "clearInterval", "Date", "nextTick", "hrtime"
]});
@fatso83
Copy link
Contributor

fatso83 commented Nov 27, 2019

Thank you for this. This seems like a valid case to check for. Want to try and have a go at fixing it? We ❤️ pull requests :)

@stale
Copy link

stale bot commented Jan 26, 2020

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.

@fatso83
Copy link
Contributor

fatso83 commented May 31, 2021

Seems fixed a long time ago

carlerik at ubuntu-i9-vm in /tmp/a 
$ node test.js 

carlerik at ubuntu-i9-vm in /tmp/a 
$ cat test.js 
const lolex = require('@sinonjs/fake-timers')
lolex.install({ now: 0, toFake: [
            "setImmediate", "clearImmediate",
            /** and others: */
            "setTimeout", "clearTimeout", "setInterval", "clearInterval", "Date", "nextTick", "hrtime"
]});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants