I was trying to mock a REST webservice that is consumed by a request-promise-powered client.
Unfortunately, nock does neither intercept the call nor is the recorder able to record the request. :(
did you solve this?
Nope. - I think this was a false negative. I still didn't fix it, but couldn't reproduce it in a controlled setup. Will reopen this issue in case I succeed in doing so.
Yep. Works like a charm. Must've been a different problem in my setup.
const nock = require('nock');
const rp = require('request-promise');nock.disableNetConnect();
let body = {country: 'fr', email: 'francoise.[email protected]', userAgent: 'Gecko/1.2.3'};
let serverMock = nock('http://www.google.com').post('/index/test', body).reply(200, 'ok');rp({
method: 'POST',
uri: 'http://www.google.com/index/test',
body: JSON.stringify(body),
headers: {
'content-type': 'application/json'
}
}).then(() => {
if (!serverMock.isDone()) {
console.log('test failed.');
} else {
console.log('test passed.');
}
});
awesome, request-promise looks like a cool module too.
I probably know why you had that problem. I had the same issue in my unit tests and took me almost 30 minutes to understand what I was doing wrong:
In my unit test module, I had an afterEach block calling nock.restore(); instead of calling nock.cleanAll();, which was disabling nock instead of cleaning up the responses.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it鈥檚 related. Thank you!
Most helpful comment
Yep. Works like a charm. Must've been a different problem in my setup.