From b9b09d5f118236cbfbf76fcf5df415cc7e72c711 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Mon, 7 Jul 2014 19:33:59 -0300 Subject: [PATCH] add stub to _request --- test/test.blockchain.Insight.js | 35 ++++++++++++--------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/test/test.blockchain.Insight.js b/test/test.blockchain.Insight.js index b96dc9cf8..18a35471f 100644 --- a/test/test.blockchain.Insight.js +++ b/test/test.blockchain.Insight.js @@ -180,29 +180,20 @@ describe('Insight model', function() { }); - it('should handle getTransaction errors', 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); - + it('should handle getTransaction null response', function(done) { 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) { ret.length.should.equal(0); done();