-
Notifications
You must be signed in to change notification settings - Fork 108
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({ toFake: ["setImmediate"] })
fails when setImmediate
is not available in context (such as browser environment)
#490
Comments
install({ toFake: ["setImmediate"] })
fails when it's not available in contextinstall({ toFake: ["setImmediate"] })
fails when setImmediate
not available in context (such as browser environment)
install({ toFake: ["setImmediate"] })
fails when setImmediate
not available in context (such as browser environment)install({ toFake: ["setImmediate"] })
fails when setImmediate
is not available in context (such as browser environment)
Good call. Whatever we do, it should be consistent. I usually like to be strict (as in throwing an error, possibly overridable with a flag), but we could also do the reverse. |
Failing with an explicit error in either case seems reasonable, but that might be considered a breaking change? |
Thanks for the follow up.
I think stop faking/providing I haven't checked properly yet, but it seems jsdom/happy-dom doesn't provide |
Absolutely, but I would also add a flag to silence those errors to have an easy fallback to the previous behaviour. That way Jest could consume |
Added the breaking change in #491 with a flag to ignore missing. That should make the behaviour consistent going forwards and maybe make introducing #323 simpler. Took a lot more effort to get the testcases working than expected, but at least it is now working. Have a look, otherwise I'll just merge in a few days. |
withGlobal
to pass context manuallyWhat did you expect to happen?
No error. Preferably allow faking
setImmediate
even when it's not available in the context, which would align with current behavior withrequestIdleCallback
,requestAnimationFrame
etc... (seerepro-other.mjs
in reproduction).What actually happens
How to reproduce
extra context of the issue
First of all, thanks for making this portable library for timer mocking!
I found some inconsistency of
@sinonjs/fake-timers
while investigating an issue on Vitest vitest-dev/vitest#5027 (comment). There is a workaround on Vitest side so it's not critical, but I thought it's worth reporting an issue.This is likely a same issue as #277 but I think the issue still persists since the verification #277 (comment) seems to be done on NodeJS where
setImmediate
is globally available but this is not the case on browsers.I'm not sure what's desired behavior, but there seems slight inconsistency whether
@sinonjs/fake-timers
fakes what's not globally available. From what I tried so far,{ toFake: ["requestIdleCallback"] }
works even when it's not globally available (for example, this is browser-only and not available on NodeJS). On the other hand,{ toFake: ["setImmediate"] }
throws an error on browser.The text was updated successfully, but these errors were encountered: