fix test that now uses through2

This commit is contained in:
Spencer Alger
2015-01-09 22:34:43 -07:00
parent 5aff12bf24
commit 547ff26104

View File

@ -306,8 +306,17 @@ describe('Transport + Mock server', function () {
});
describe('sniffOnConnectionFault', function () {
it('schedules a sniff when sniffOnConnectionFault is set and a connection failes', function (done) {
var clock = sinon.useFakeTimers('setTimeout');
var clock;
beforeEach(function () {
clock = sinon.useFakeTimers('setTimeout');
});
afterEach(function () {
clock.restore();
});
it('schedules a sniff when sniffOnConnectionFault is set and a connection failes', function () {
var serverMock = nock('http://esbox.1.com')
.get('/')
.reply(200, function () {
@ -315,6 +324,10 @@ describe('Transport + Mock server', function () {
cb(new Error('force error'));
});
setTimeout(function () {
str.write('');
}, 10);
str.setEncoding = function () {}; // force nock's isStream detection
return str;
});
@ -331,19 +344,19 @@ describe('Transport + Mock server', function () {
tran.request({
requestTimeout: Infinity
}).then(
_.partial(done, new Error('expected the request to fail')),
function (err) {
expect(ConnectionPool.prototype._onConnectionDied.callCount).to.eql(1);
expect(tran.sniff.callCount).to.eql(0);
expect(_.size(clock.timeouts)).to.eql(1);
var timeout = _.values(clock.timeouts).pop();
timeout.func();
expect(tran.sniff.callCount).to.eql(1);
clock.restore();
done();
}
);
})
.then(function () {
throw new Error('expected the request to fail');
})
.catch(function (err) {
expect(ConnectionPool.prototype._onConnectionDied.callCount).to.eql(1);
expect(tran.sniff.callCount).to.eql(0);
expect(_.size(clock.timeouts)).to.eql(1);
var timeout = _.values(clock.timeouts).pop();
timeout.func();
expect(tran.sniff.callCount).to.eql(1);
});
});
});
});