diff --git a/lib/index.ts b/lib/index.ts index adf83788..5a4ace28 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -75,7 +75,7 @@ export default class Backburner { platform.clearTimeout = _platform.clearTimeout || ((id) => clearTimeout(id)); platform.next = _platform.next || ((fn) => platform.setTimeout(fn, 0)); platform.clearNext = _platform.clearNext || platform.clearTimeout; - platform.now = _platform.now || Date.now; + platform.now = _platform.now || (() => Date.now()); this._platform = platform; diff --git a/tests/set-timeout-test.ts b/tests/set-timeout-test.ts index d59cbf0d..5a17c31b 100644 --- a/tests/set-timeout-test.ts +++ b/tests/set-timeout-test.ts @@ -50,17 +50,20 @@ QUnit.test('later', function(assert) { }, 20); }); -QUnit.test('later can continue when `Date.now` is monkey-patched', function(assert) { +QUnit.test('later should rely on stubbed `Date.now`', function(assert) { assert.expect(1); - let arbitraryTime = +new Date(); let bb = new Backburner(['one']); let done = assert.async(); + let globalNowWasUsed = false; - Date.now = function() { return arbitraryTime; }; + Date.now = function() { + globalNowWasUsed = true; + return originalDateNow(); + }; bb.later(() => { - assert.ok(true); + assert.ok(globalNowWasUsed); done(); }, 1); });