diff options
author | Oleg <markelog@gmail.com> | 2014-01-13 22:22:51 +0400 |
---|---|---|
committer | Oleg <markelog@gmail.com> | 2014-01-13 22:22:51 +0400 |
commit | f1af3c23f9fbef69b69868773fd01b4950ae2f9f (patch) | |
tree | 4515723e60bd8c41c5ade56f82ef0d372afdc37e | |
parent | c991edd2e20949bdd18616ce7736e0c0d67eede0 (diff) | |
download | jquery-f1af3c23f9fbef69b69868773fd01b4950ae2f9f.tar.gz jquery-f1af3c23f9fbef69b69868773fd01b4950ae2f9f.zip |
Tests: Fix sinon timers for oldIE
-rw-r--r-- | Gruntfile.js | 3 | ||||
-rw-r--r-- | test/index.html | 1 | ||||
-rw-r--r-- | test/libs/sinon/timers_ie.js | 27 | ||||
-rw-r--r-- | test/unit/effects.js | 9 |
4 files changed, 36 insertions, 4 deletions
diff --git a/Gruntfile.js b/Gruntfile.js index ada6baa4b..0f5c32ba7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -60,7 +60,8 @@ module.exports = function( grunt ) { files: { "qunit": "qunit/qunit", "require.js": "requirejs/require.js", - "sinon/fake_timers.js": "sinon/lib/sinon/util/fake_timers.js" + "sinon/fake_timers.js": "sinon/lib/sinon/util/fake_timers.js", + "sinon/timers_ie.js": "sinon/lib/sinon/util/timers_ie.js" } } }, diff --git a/test/index.html b/test/index.html index ce19c4d5e..bfadff7f8 100644 --- a/test/index.html +++ b/test/index.html @@ -17,6 +17,7 @@ <script src="libs/qunit/qunit.js"></script> <script src="libs/require.js"></script> <script src="libs/sinon/fake_timers.js"></script> + <script src="libs/sinon/timers_ie.js"></script> <!-- See testinit for the list of tests --> <script src="data/testinit.js"></script> diff --git a/test/libs/sinon/timers_ie.js b/test/libs/sinon/timers_ie.js new file mode 100644 index 000000000..7903a0e78 --- /dev/null +++ b/test/libs/sinon/timers_ie.js @@ -0,0 +1,27 @@ +/*global sinon, setTimeout, setInterval, clearTimeout, clearInterval, Date*/ +/** + * Helps IE run the fake timers. By defining global functions, IE allows + * them to be overwritten at a later point. If these are not defined like + * this, overwriting them will result in anything from an exception to browser + * crash. + * + * If you don't require fake timers to work in IE, don't include this file. + * + * @author Christian Johansen (christian@cjohansen.no) + * @license BSD + * + * Copyright (c) 2010-2013 Christian Johansen + */ +function setTimeout() {} +function clearTimeout() {} +function setInterval() {} +function clearInterval() {} +function Date() {} + +// Reassign the original functions. Now their writable attribute +// should be true. Hackish, I know, but it works. +setTimeout = sinon.timers.setTimeout; +clearTimeout = sinon.timers.clearTimeout; +setInterval = sinon.timers.setInterval; +clearInterval = sinon.timers.clearInterval; +Date = sinon.timers.Date; diff --git a/test/unit/effects.js b/test/unit/effects.js index 4f75dddf2..b3916b4a5 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -5,18 +5,21 @@ if ( !jQuery.fx ) { return; } -var off = jQuery.fx.off; +var off = jQuery.fx.off, + oldNow = jQuery.now; module("effects", { setup: function() { this.clock = sinon.useFakeTimers( 505877050 ); this._oldInterval = jQuery.fx.interval; jQuery.fx.interval = 10; - jQuery.now = Date.now; + jQuery.now = function() { + return +( new Date() ); + }; }, teardown: function() { this.clock.restore(); - jQuery.now = Date.now; + jQuery.now = oldNow; jQuery.fx.stop(); jQuery.fx.interval = this._oldInterval; jQuery.fx.off = off; |