Skip to content

Instantly share code, notes, and snippets.

@dallonf
Last active November 29, 2016 16:52
Show Gist options
  • Save dallonf/2d824185f543323c51b3f6f7406ec145 to your computer and use it in GitHub Desktop.
Save dallonf/2d824185f543323c51b3f6f7406ec145 to your computer and use it in GitHub Desktop.
const nock = require('nock');
const test = require('tap').test;
const superagent = require('superagent');
test('reqheaders ignored #748 - test matching', t => {
nock('http://www.example.com', {
reqheaders: {
'authorization': 'Bearer TOKEN'
}
})
.get('/users/52')
.query(true)
.reply(200);
return superagent.get('http://www.example.com/users/52')
.set('authorization', 'Bearer TOKEN')
.then(res => {
t.equal(res.statusCode, 200);
});
});
test('reqheaders ignored #748 - test missing header', t => {
nock('http://www.example.com', {
reqheaders: {
'authorization': 'Bearer TOKEN'
}
})
.get('/users/52')
.query(true)
.reply(200);
return superagent.get('http://www.example.com/users/52')
.then(() => {
t.ok(false, 'Request should not have succeeded')
}, err => {
t.type(err, 'object');
t.equal(err.statusCode, 404);
t.ok(err.message.match(/No match/));
});
});
test('reqheaders ignored #748 - test different header', t => {
nock('http://www.example.com', {
reqheaders: {
'authorization': 'Bearer TOKEN'
}
})
.get('/users/52')
.query(true)
.reply(200);
return superagent.get('http://www.example.com/users/52')
.set('authorization', 'Bearer OTHER TOKEN')
.then(() => {
t.ok(false, 'Request should not have succeeded')
}, err => {
t.type(err, 'object');
t.equal(err.statusCode, 404);
t.ok(err.message.match(/No match/));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment