Last active
May 4, 2017 10:06
-
-
Save wrumsby/5335617 to your computer and use it in GitHub Desktop.
Example of how to use Sinon's useFakeTimers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global define, describe, it, before, after */ | |
define(['chai', 'sinon', 'boilerplate/simple'], function (chai, sinon, simple) { | |
'use strict'; | |
var assert = chai.assert; | |
describe('simple', function () { | |
describe('stamp', function () { | |
var clock; | |
before(function () { | |
var date = new Date(2013, 3, 1); | |
clock = sinon.useFakeTimers(date.getTime()); | |
}); | |
it('should append the date to the given value', function () { | |
var actual = simple.stamp('test'); | |
assert.equal(actual, 'test:2013-04-01'); | |
}); | |
after(function () { | |
clock.restore(); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To make this more resilient, your test should really be: