Skip to content

Instantly share code, notes, and snippets.

@vrinek
Created November 25, 2016 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrinek/f20aa9649af3642120fb65706cb9ac88 to your computer and use it in GitHub Desktop.
Save vrinek/f20aa9649af3642120fb65706cb9ac88 to your computer and use it in GitHub Desktop.
const nock = require('../.');
const test = require('tap').test;
const request = require('request');
test('reqheaders ignored #748 - test matching', t => {
nock('http://www.example.com', {
reqheaders: {
'authorization': 'Bearer TOKEN'
}
})
.get('/users/52')
.query(true)
.reply(200);
request({
method: 'GET',
uri: 'http://www.example.com/users/52',
headers: {
'authorization': 'Bearer TOKEN'
}
}, function(err, res, body) {
t.type(err, 'null');
t.equal(res.statusCode, 200);
t.end();
});
});
test('reqheaders ignored #748 - test missing header', t => {
nock('http://www.example.com', {
reqheaders: {
'authorization': 'Bearer TOKEN'
}
})
.get('/users/52')
.query(true)
.reply(200);
request({
method: 'GET',
uri: 'http://www.example.com/users/52'
}, function(err, res, body) {
t.type(res, 'undefined');
t.type(err, 'object');
t.equal(err.statusCode, 404);
t.ok(err.message.match(/No match/));
t.end();
});
});
test('reqheaders ignored #748 - test different header', t => {
nock('http://www.example.com', {
reqheaders: {
'authorization': 'Bearer TOKEN'
}
})
.get('/users/52')
.query(true)
.reply(200);
request({
method: 'GET',
uri: 'http://www.example.com/users/52',
headers: {
'authorization': 'Bearer OTHER TOKEN'
}
}, function(err, res, body) {
t.type(res, 'undefined');
t.type(err, 'object');
t.equal(err.statusCode, 404);
t.ok(err.message.match(/No match/));
t.end();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment