Why nock throw error `Nock: No match for request` when repeating request
See original GitHub issueTests case:
nock('https://xxxx.com').get('/').times(1).reply(200, { mock: 1 });
// first times: print { mock: 1 }
// second and third times: throw error `Nock: No match for request`
for (let i = 0; i < 3; i++) {
const {data} = await axios({
url: 'https://xxxx.com/',
method: 'GET',
});
console.log(data);
}
In README, means you can get real response from url you specified but not an error.
But in your tests cases: It should get error when repeating.
Version
- Nodejs: v12
- Nock: 13.0.7
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Error: Nock: No match for request - Stack Overflow
I am calling 2 apis, 1 is post and 1 is get. And doing Promise.all([1stApi, 2edApi]). But getting error as - Error: Nock:...
Read more >[Solved]-Error: Nock: No match for request-node.js
It looks like you only setup interceptor once and expect it to work for every request. If you want your interceptors to persist...
Read more >Nock - JavaScripting
If no request headers are specified for mocking then Nock will automatically skip matching of request headers. Since the host header is a...
Read more >No match error when testing an Express.js controller doing ...
The solution was to append the call to the .persist() method between nock('http://backend') and get('/user/details') as shown in code below:
Read more >HTTP Server mocking for Node.js
function activate() { if(originalClientRequest) { throw new Error('Nock already ... Enable/Disable real HTTP request As default, if you do not mock a host, ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Agreed, the docs need updating. PRs welcome!
@marcusNumminen to achieve your original, expected behavior the
allowUnmocked
flag needs to be passed when creating a Scope. https://github.com/nock/nock#allow-unmocked-requests-on-a-mocked-hostnameNo, you will get an error from the fifth call. See this tests case https://github.com/nock/nock/blob/main/tests/test_repeating.js README and the logic of code do not match.