Skip to content

Instantly share code, notes, and snippets.

@hitsujiwool
Last active August 29, 2015 13:57
Show Gist options
  • Save hitsujiwool/9462896 to your computer and use it in GitHub Desktop.
Save hitsujiwool/9462896 to your computer and use it in GitHub Desktop.
var sinon = require('sinon');
var assert = require('assert');
function async(cb) {
setTimeout(function() {
cb();
}, 1000);
}
describe('async()', function() {
it('should call callback', function() {
var clock = sinon.useFakeTimers('setTimeout');
var cb = sinon.spy();
async(cb);
clock.tick(999999);
assert(cb.called);
});
});
var sinon = require('sinon');
var assert = require('assert');
var http = require('http');
var nock = require('nock');
function async(cb) {
http.request({ hostname: 'localhost', path: '/' }, function(res) {
res.on('end', function() {
cb();
});
}).end();
}
describe('async()', function() {
it('should call callback', function(done) {
var clock = sinon.useFakeTimers('setTimeout');
var api = nock('http://localhost')
.get('/')
.reply(200);
var cb = sinon.spy();
async(cb);
clock.tick(999999);
assert(cb.called);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment