Skip to content

Commit

Permalink
Fix nock.removeInterceptor can remove the wrong Intercept
Browse files Browse the repository at this point in the history
I'll add a proper test if you accept the general solution.
  • Loading branch information
mikicho committed Jul 13, 2023
1 parent bd4783b commit db51287
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lib/intercept.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ function removeInterceptor(options) {
let baseUrl, key, method, proto
if (options instanceof Interceptor) {
baseUrl = options.basePath
key = options._key
} else {
proto = options.proto ? options.proto : 'http'

Expand All @@ -224,7 +223,7 @@ function removeInterceptor(options) {
) {
for (let i = 0; i < allInterceptors[baseUrl].interceptors.length; i++) {
const interceptor = allInterceptors[baseUrl].interceptors[i]
if (interceptor._key === key) {
if (interceptor === options || interceptor._key === key) {
allInterceptors[baseUrl].interceptors.splice(i, 1)
interceptor.scope.remove(key, interceptor)
break
Expand Down

0 comments on commit db51287

Please sign in to comment.