Skip to content

Commit

Permalink
test: Add two tests for reply cbs #1170
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardLitt authored and gr2m committed Sep 9, 2018
1 parent 6a0d74e commit d794d35
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/test_intercept.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,48 @@ test("get with reply callback returning array with headers", function(t) {
});
});

test("get with reply callback returning default statusCode without body", function(t) {
nock('http:https://replyheaderland')
.get('/')
.reply(function(uri, requestBody) {
return [401];
});

http.get({
host: "replyheaderland",
path: '/',
port: 80,
}, function(res) {
res.setEncoding('utf8');
t.equal(res.statusCode, 200);
res.on('data', function(data) {
t.equal(data, '[401]');
res.once('end', t.end.bind(t));
});
});
});

test("get with reply callback returning callback without headers", function(t) {
nock('http:https://replyheaderland')
.get('/')
.reply(function() {
return [401, 'This is a body'];
});

http.get({
host: "replyheaderland",
path: '/',
port: 80,
}, function(res) {
res.setEncoding('utf8');
t.equal(res.statusCode, 401);
res.on('data', function(data) {
t.equal(data, 'This is a body');
res.once('end', t.end.bind(t));
});
});
});

test("post with reply callback, uri, and request body", function(t) {
var input = 'key=val';

Expand Down

0 comments on commit d794d35

Please sign in to comment.