sinonjs / sinon

Test spies, stubs and mocks for JavaScript.
https://sinonjs.org/
Other
9.63k stars 770 forks source link

clock.tick() broken in modern browsers #506

Closed Krinkle closed 10 years ago

Krinkle commented 10 years ago

No longer works as expected when upgrading from v1.9.1 to v1.10.2. The clearing phase always fails fatally with:

Uncaught TypeError: Cannot read property 'id' of null sinon-1.10.2.js:3112

clearTimeout sinon-1.10.2.js:3112
clearInterval sinon-1.10.2.js:3124
global.(anonymous function) sinon-1.10.2.js:3330
jQuery.fx.stop
jQuery.fx.tick
sinon.sinon.clock.callTimer sinon-1.10.2.js:3202
tick sinon-1.10.2.js:3147
(anonymous function) example.test.js:50
Test.run jquery.qunit.js:1297
(anonymous function) jquery.qunit.js:1463
process jquery.qunit.js:1016
(anonymous function)

Caused by #451 as the timerId variable can be null there, which is also typeof object.

Krinkle commented 10 years ago

Downstream example:

setup:
  var config = sinon.getConfig( sinon.config );
  config.injectInto = this;
  sinon.sandbox.create( config );
teardown:
   this.sandbox.verifyAndRestore();
  this.clock = this.sandbox.useFakeTimers();
...
  this.clock.tick( 500 );

Regression:

12:59:34 >> TypeError: 'null' is not an object (evaluating 'timerId.id')
Krinkle commented 10 years ago

Seems fixed as of 5f45d2e89ca7c2495ab8ae3b6709ed590d4ca0f1. Could this please be made in a minor release considering it is a fatal regression?

cjohansen commented 10 years ago

Done! Thanks for the heads up