Error: Nock: No Match for Request
I Am Receiving Following Error { Error: { Error: Nock: No Match for Request { "Method": "Get", "Url": "", "Headers": { "Content-Type": "Application/Json"...
I am receiving following error
{ error:
{ Error: Nock: No match for request {
"method": "GET",
"url": "",
"headers": {
"content-type": "application/json",
"host": "localhost:3000"
}
} Got instead {
"method": "GET",
"url": "",
"headers": {
"content-type": "application/json",
"host": "localhost:3000"
}
}
The url is as expected, not sure what's wrong, any pointer?
5 Answers
Use .log(console.log) to see the exact error message.
EX :
nock(')
.persist()
.log(console.log)
.get('/test')
.query({})
.reply(200, response);
When you use this and run the test, you will see something like this in the console
matching to GET with query({}): **true/false**.
If it says true, your request should be good. But if it says false, check both the requests and make sure they match.
Nock interceptors don't persist by default. For every request nock needs an interceptor. It looks like you only setup interceptor once and expect it to work for every request. If you want your interceptors to persist use .persist() option something like below.
var scope = nock(')
.persist()
.get(/.*/)
.reply(200, 'Nock all get requests!');
you can display at any time prepared nocks, it's almost always a typo... ;)
console.log(nock.activeMocks());
(debuger in webstorm sucks and nock is undefined)
sometimes can be a encodedQueryParams: true option the problem
encoding query params is default behaviour these days, works well without such an option
Mostly a typo. In my case I had to add a / before the string in get method.
.get('/list')