What did you expect to happen?
No warnings
What actually happens
When window.addEventListener is stubbed, it gets called, and then expect(window.addEventListener).toHaveBeenCalled() is called, I get these warnings (with stacktraces):
sinon.js:1547 'window.webkitStorageInfo' is deprecated. Please use 'navigator.webkitTemporaryStorage' or 'navigator.webkitPersistentStorage' instead.
toString @ sinon.js:1547
n @ sinon.js:2875
(anonymous function) @ sinon.js:2786
printf @ sinon.js:2782
expectedSpy @ jasmine-sinon.js:36
(anonymous function) @ jasmine-sinon.js:20
compare @ jasmine-sinon.js:198
(anonymous function) @ jasmine.js:1480
(anonymous function) @ default.spec.js:1489
attemptSync @ jasmine.js:1886
QueueRunner.run @ jasmine.js:1874
(anonymous function) @ jasmine.js:1898
(anonymous function) @ jasmine.js:1842
_callee32$ @ default.spec.js:1461
tryCatch @ runtime.js:62
invoke @ runtime.js:336
prototype.(anonymous function) @ runtime.js:95
step @ asyncToGenerator.js:17
(anonymous function) @ asyncToGenerator.js:28
sinon.js:1547 'webkitIndexedDB' is deprecated. Please use 'indexedDB' instead.
toString @ sinon.js:1547
n @ sinon.js:2875
(anonymous function) @ sinon.js:2786
printf @ sinon.js:2782
expectedSpy @ jasmine-sinon.js:36
(anonymous function) @ jasmine-sinon.js:20
compare @ jasmine-sinon.js:198
(anonymous function) @ jasmine.js:1480
(anonymous function) @ default.spec.js:1489
attemptSync @ jasmine.js:1886
QueueRunner.run @ jasmine.js:1874
(anonymous function) @ jasmine.js:1898
(anonymous function) @ jasmine.js:1842
_callee32$ @ default.spec.js:1461
tryCatch @ runtime.js:62
invoke @ runtime.js:336
prototype.(anonymous function) @ runtime.js:95
step @ asyncToGenerator.js:17
(anonymous function) @ asyncToGenerator.js:28
How to reproduce
The stacktrace above is from my original test code, but I was able to boil down the code to reproduce the warnings to the code below:
import { stub } from 'sinon';
describe('when examining a stubbed window function', () => {
beforeEach(() => {
stub(window, 'addEventListener');
window.addEventListener('beforeunload', () => {});
});
it('will get deprecation warnings', () => {
expect(window.addEventListener).toHaveBeenCalled();
});
});
This is happening because toString is iterating over all of window's properties and when the deprecated properties are read, the warnings are output.
Thank you for reporting this issue, I've observed it myself when running tests in Chrome, and wanted to spend some time looking into it. Your analysis is correct, it is indeed functionToString that triggers the warning.
The source of that function is unchanged in Sinon 2.x, so the warning will also be triggered there.
The fact that Sinon.JS is triggering a deprecation warning in Chrome, is an unfortunate side effect of a design decision in Chrome. Sooner or later, Chrome will remove the API again, and the deprecation warning will go away.
With that in mind, I don't think this is an issue that should be fixed in Sinon.JS.
Modernizer was confronted with the same issue and came to the same decision: https://github.com/Modernizr/Modernizr/issues/866
Further reading:
One way of avoiding this deprecation warning (and making your tests able to run in many more runtimes) is to use a wrapper for accessing browser globals, and then using the wrapper as a stubbing target. You can either roll your own, or use a pre-made one like wrapple
I think this should be closed if we are not to do anything about it.
I am getting these warnings
'window.webkitStorageInfo' is deprecated. Please use 'navigator.webkitTemporaryStorage' or 'navigator.webkitPersistentStorage' instead.
copyKey @ modules.js?hash=80ddce2…:505
(anonymous) @ modules.js?hash=80ddce2…:831
syncExportsToNamespace @ modules.js?hash=80ddce2…:824
Ep.runGetters @ modules.js?hash=80ddce2…:781
Ep.runSetters @ modules.js?hash=80ddce2…:868
runSetters @ modules.js?hash=80ddce2…:431
fileEvaluate @ modules-runtime.js?hash=8587d18…:360
require @ modules-runtime.js?hash=8587d18…:238
_export.js @ modules.js?hash=80ddce2…:3711
fileEvaluate @ modules-runtime.js?hash=8587d18…:343
require @ modules-runtime.js?hash=8587d18…:238
es6.symbol.js @ modules.js?hash=80ddce2…:3412
fileEvaluate @ modules-runtime.js?hash=8587d18…:343
require @ modules-runtime.js?hash=8587d18…:238
runtime.js @ ecmascript-runtime-client.js?hash=2360330…:32
fileEvaluate @ modules-runtime.js?hash=8587d18…:343
require @ modules-runtime.js?hash=8587d18…:238
(anonymous) @ ecmascript-runtime-client.js?hash=2360330…:97
(anonymous) @ ecmascript-runtime-client.js?hash=2360330…:110
modules.js?hash=80ddce2…:505 'webkitIndexedDB' is deprecated. Please use 'indexedDB' instead.
copyKey @ modules.js?hash=80ddce2…:505
(anonymous) @ modules.js?hash=80ddce2…:831
syncExportsToNamespace @ modules.js?hash=80ddce2…:824
Ep.runGetters @ modules.js?hash=80ddce2…:781
Ep.runSetters @ modules.js?hash=80ddce2…:868
runSetters @ modules.js?hash=80ddce2…:431
fileEvaluate @ modules-runtime.js?hash=8587d18…:360
require @ modules-runtime.js?hash=8587d18…:238
_export.js @ modules.js?hash=80ddce2…:3711
fileEvaluate @ modules-runtime.js?hash=8587d18…:343
require @ modules-runtime.js?hash=8587d18…:238
es6.symbol.js @ modules.js?hash=80ddce2…:3412
fileEvaluate @ modules-runtime.js?hash=8587d18…:343
require @ modules-runtime.js?hash=8587d18…:238
runtime.js @ ecmascript-runtime-client.js?hash=2360330…:32
fileEvaluate @ modules-runtime.js?hash=8587d18…:343
require @ modules-runtime.js?hash=8587d18…:238
(anonymous) @ ecmascript-runtime-client.js?hash=2360330…:97
(anonymous) @ ecmascript-runtime-client.js?hash=2360330…:110
@parveen-daffodil, why did you post that thread dump? Did you not read the issue and our comments leading to closing it?
@fatso83 Oh, I see this now. Thanks.
so we are just going to ignore it?
so we are just going to ignore it?
@kaden-tech please see this comment https://github.com/sinonjs/sinon/issues/1202#issuecomment-267307362
Most helpful comment
This is happening because toString is iterating over all of window's properties and when the deprecated properties are read, the warnings are output.