-
-
Notifications
You must be signed in to change notification settings - Fork 769
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
Mocha.js and useFakeTimers giving global leak errors #143
Comments
I guess overwriting, then restoring these functions causes these properties to have their |
@visionmedia we may want to change the global leak detection to allow overwriting of existing global tokens. |
overwriting existing ones shouldn't trigger it, we just check the names not the values |
By the time the test completes (i.e. after |
ah I see, that might be the case. gotta love them prop descriptors |
So is there something I can do to help? |
My suggestion is that mocha not care about "leaking" known globals. If you want to help I guess you could research whether it's possible to overwrite window.setTimeout and then restoring it again without making it enumerable in all browses. I suspect you can't, but I'm not sure |
@cjohansen how can I check if something is enumerable? |
@cjohansen yeah that seems to be the case: Object.keys(window)
["window", "top", "location", "external", "chrome", "v8Locale", "document", "html5", "Modernizr", "$", "jQuery", "jQuery1720022294572554528713", "moment", "GitHub", "BaconPlayer", "DateInput", "clippyCopiedCallback", "debug", "_gaq", "_gauges", "$stats", "_gat", "gaGlobal"] I'll open an issue for mocha |
@cjohansen @visionmedia There's a couple solutions that wouldn't require a change to Mocha (which IMO shouldn't be necessary).
Note that @camwest You can check with |
@domenic If I can define these methods on |
@cjohansen Support for But ugh, tested in IE7 and IE8 modes of IE10, and that doesn't work either ( |
shouldn't |
@neonstalwart to be honest, I can't remember if I tried (haven't looked into this for ~2 years). If someone wants to do the research (remember, Sinon still supports IE6/7) I'll be happy to change this for the better. |
@cjohansen @neonstalwart i did some research on ie 6 and 8. The way sinon define things like setTimeout on those platforms is like so:
this is done so that window.setTimeout becomes writeable. Unfortunately this also has a side effect of making window.setTimeout not configurable. The only way to make a property configurable again is with Object.defineProperty, which unfortunately doesn't work pre ie9. When a property is not configurable, the delete operator doesn't work on it any longer. |
Is there a way to make |
I experimented with simply setting window.blah = blah, but to no avail. At this point i'm happy that we can mock setTimeout at all in IE. |
I think a fix for modern browsers first, then for IE 6 + 7 will fix this issue for most users. |
Also, you can just disable the global leaks test for certain functions: mocha.setup({globals: ['setTimeout', 'setInterval', 'clearTimeout', 'clearInterval']}); Will fix this problem. It's also available in the command line as |
I recently patched mocha to do just that by default. |
I could not find a way to specify the globals when using Karma, given the mocha adapter is setting |
I'll mark this for |
I don't think the trade-off in worse browser support for this is worth it at the moment. @domenic's proposal can be implemented at a later point, but I'm closing this issue for now. |
Is it possible to mitigate this by only setting I'm assuming that most of Sinon's features do not require this. |
I get this error when running Mocha 1.1.0 and sinon 1.3.4
Error: global leaks detected: setTimeout, setInterval, clearTimeout, clearInterval
The text was updated successfully, but these errors were encountered: