unit.js
Version:
Simple, intuitive and flexible unit testing framework for javascript / Node.js (browser and server). Integrates awesome assertions libraries like Must.js, Should.js, Assert of Node.js, Sinon.js and other friendly features (promise, IoC, plugins, ...).
44 lines (32 loc) • 819 B
JavaScript
/**
* This file is part of the Unit.js testing framework.
*
* (c) Nicolas Tallefourtane <dev@nicolab.net>
*
* For the full copyright and license information, please view
* the LICENSE file distributed with this source code
* or visit http://unitjs.com.
*
* @author Nicolas Tallefourtane <dev@nicolab.net>
*/
;
var test = require('../../src');
describe('Faking time', function() {
var clock;
before(function() {
clock = test.useFakeTimers();
});
after(function() {
clock.restore();
});
it('calls callback after 100ms', function() {
var spy = test.spy();
setTimeout(spy, 100);
clock.tick(99);
test.assert(spy.notCalled);
clock.tick(1);
test.assert(spy.calledOnce);
// Also:
test.assert.strictEqual(new Date().getTime(), 100);
});
});