-
-
Save dualcyclone/0480ccab01aa89383c37429d3be6cb64 to your computer and use it in GitHub Desktop.
Example of how to use Sinon's useFakeTimers.
This file contains hidden or 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; | |
var mockDate; | |
before(function () { | |
var date = new Date(2013, 3, 1); | |
// Maintaining use of fake timers for Date | |
clock = sinon.useFakeTimers(date.getTime()); | |
// Implementing method to be able to assert calls to Date | |
mockDate = sinon.spy(global, 'Date'); | |
}); | |
it('should append the date to the given value', function () { | |
var actual = simple.stamp('test'); | |
var expected = 'test:' + date.getFullYear() + '-' + ("0" + (date.getMonth() + 1)).slice(-2) + '-' + ("0" + date.getDate()).slice(-2); | |
assert.equal(actual, expected); | |
expect(mockDate.calledWithNew()).to.be.true; | |
}); | |
after(function () { | |
clock.restore(); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment