Skip to content
This repository has been archived by the owner on Apr 27, 2023. It is now read-only.

Commit

Permalink
add test for request failing
Browse files Browse the repository at this point in the history
  • Loading branch information
mike182uk committed Jan 10, 2016
1 parent c0b7a29 commit 28a2be2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"jscs": "^2.8.0",
"jshint": "^2.9.1-rc2",
"nock": "^5.2.1",
"rewire": "^2.5.1",
"tap-spec": "^4.1.1",
"tape": "^4.4.0"
}
Expand Down
23 changes: 22 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var nock = require('nock');
var rewire = require('rewire');
var test = require('tape');

var fetchGists = require('./index');
var fetchGists = rewire('./index');

var accessToken = 'TEST123';

Expand Down Expand Up @@ -94,6 +95,26 @@ test('error occurs when response code is not 200, 401 or 403', function (t) {
})
});

test('error occurs when request fails', function (t) {
nock.cleanAll();

t.plan(1);

mockGetGistsApiCall(1, [], true, 200)

var responseError = 'foo'

var revert = fetchGists.__set__('request', function (opts, cb) {
cb(responseError);
});

fetchGists(accessToken).catch(function (error) {
t.equal(responseError, error, 'error occured during request');
});

revert();
});

function mockGetGistsApiCall (page, body, isLastPage, statusCode) {
var statusCode = statusCode || 200;
var respHeaders = {};
Expand Down

0 comments on commit 28a2be2

Please sign in to comment.