I cannot for the life of me get nock to work with a simple superagent post request. Here is both my superagent and nock configuration.
superagent:
request
.post('https://test.com/api/login')
.send({
email: '[email protected]',
password: 'testpassword'
})
.end((err, res) => {
if (err) {
console.log(err);
}
});
nock:
nock('https://test.com')
.post('/api/login')
.send({
email: '[email protected]',
password: 'testpassword'
})
.reply(200, {
id: 1,
token: 'abc'
});
I'm receiving the following error from nock:
{ [Error: Nock: No match for request POST https://test.com/api/login {"email":"[email protected]","password":"testpassword"}] status: 404, statusCode: 404, response: undefined }
Another weird aspect is that this error is being logged in my superagent response handler. So I know the call is being made and intercepted.
Ok -- figured it out. After digging through the docs a bit more I found the .log function. I chained my nock config like so
nock('https://test.com')
.log(console.log)...
and it turns out the request bodies were not matching.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With