Tests aren't cleaning up nock scope correctly
See original GitHub issueNoticed while testing https://github.com/node-nock/nock/pull/704:
- On that PR’s branch, check out be1533746bc728bf3f136aaf9924aa10e7031bf5.
- Run
./node_modules/.bin/tap --harmony -R spec ./tests/test_intercept.js
. It’ll fail onquery() will not match when the path has no query
. - Comment out the tests above it, lines 28-4844, and run the test again – now it passes.
- Un-comment the tests, add
nock.cleanAll();
on line 4847, and run it again – it still passes.
This suggests to me that something is leaking across the tests.
I’m not familiar with the tap
library, but I don’t see any beforeEach
or afterEach
mechanism in its docs.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:17 (8 by maintainers)
Top Results From Across the Web
Reset pendingMocks on nock scope - node.js - Stack Overflow
I'm trying to run multiple assertions against a nock scope and mock the ... pendingMocks() with requests even after I've cleaned all with:...
Read more >Testing Code | Lecstor's Blog
In tests, call isDone on each nock scope before checking the result. If you check the result first, and the nock scope after,...
Read more >How to Test External APIs with Nock - The New Stack
The most thorough way is to spin up the service locally using a Docker image of it. Granted, the setup is a little...
Read more >nock reset between tests | The AI Search Engine You Control
There is a way to do before hooks in tap, however it appears to require nesting the tests. Another advantage of resetting state...
Read more >nock - npm
On your test, you can setup your mocking object like this: const nock = require('nock') const scope = nock('https://api.github.com') ...
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
I’ve tried numerous different setup and teardown strategies and cannot get multiple tests to run properly with nock (running mocha and supertest). For instance:
package.json:
I also faced with this issue. I clean up all mocks with
and in every test I mock the same endpoint.
Test 1 respond with 500 Test 2 respond with 200
but now I get 500 in Test 2 because
Nock.pendingMocks()
still contains two entrys 😦nock: 9.0.13
NodeJs 8