-
-
Notifications
You must be signed in to change notification settings - Fork 745
Closed
Description
Please avoid duplicates
- I checked all open bugs and none of them matched my problem.
Reproducible test case
Nock Version
13.2.9
Node Version
16.17.0
TypeScript Version
No response
What happened?
nock.removeIntercept
searches for a "matching nock" even when provided the exact nock that needs to be removed. The search algorithm is inadequate such that it can remove the wrong nock if there are multiple nocks on the same root uri with different query parameters.
const nock = require("nock");
const assert = require("assert");
const searchScope = nock("http://fakeSearch.com");
const puppyNockIntercept = searchScope.get("/search?q=puppies");
puppyNockIntercept.reply(200, { puppies: [] });
const kittenNockIntercept = searchScope.get("/search?q=kittens");
kittenNockIntercept.reply(200, { kittens: [] });
nock.removeInterceptor(kittenNockIntercept);
const remainingNocks =
searchScope.keyedInterceptors["GET http://fakesearch.com:80/search"];
assert(remainingNocks.length === 1, "Only 1 nock remains");
const remainingNock = remainingNocks[0];
assert(
remainingNock.uri === "/search?q=kittens",
"The puppies nock was removed instead of kittens"
);
Would you be interested in contributing a fix?
- yes