Last active
November 29, 2016 16:52
-
-
Save dallonf/2d824185f543323c51b3f6f7406ec145 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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