add stub to _request
This commit is contained in:
parent
1cb10219e9
commit
b9b09d5f11
1 changed files with 10 additions and 19 deletions
|
|
@ -180,29 +180,20 @@ describe('Insight model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should handle getTransaction errors', function(done) {
|
it('should handle getTransaction null response', function(done) {
|
||||||
|
|
||||||
var http = require('http');
|
|
||||||
var request = {
|
|
||||||
statusCode: 200
|
|
||||||
};
|
|
||||||
|
|
||||||
request.on = function(event, cb) {
|
|
||||||
if (event === 'error') return;
|
|
||||||
if (event === 'data') return cb('{ "txid": "1234" }');
|
|
||||||
return cb();
|
|
||||||
};
|
|
||||||
|
|
||||||
var req = {};
|
|
||||||
req.write = function() {};
|
|
||||||
req.end = function() {};
|
|
||||||
|
|
||||||
sinon
|
|
||||||
.stub(http, 'request')
|
|
||||||
.returns(req)
|
|
||||||
.yields(request);
|
|
||||||
|
|
||||||
var w = new Insight();
|
var w = new Insight();
|
||||||
|
w._request = sinon.stub().yields();
|
||||||
|
w.getTransactions(['asdasd'], function(ret) {
|
||||||
|
ret.length.should.equal(0);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
it('should handle getTransaction empty response', function(done) {
|
||||||
|
var w = new Insight();
|
||||||
|
w._request = sinon.stub().yields([]);
|
||||||
w.getTransactions(['asdasd'], function(ret) {
|
w.getTransactions(['asdasd'], function(ret) {
|
||||||
ret.length.should.equal(0);
|
ret.length.should.equal(0);
|
||||||
done();
|
done();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue