Skip to content

nock.removeInterceptor with an Interceptor instance does not remove it from its scope #2353

@mbargiel

Description

@mbargiel

Please avoid duplicates

Reproducible test case

See example snippet in description.

Nock Version

13.2.4

Node Version

16.13.1

TypeScript Version

No response

What happened?

Removing interceptors through nock.removeInterceptor correctly removes them from pending and active mocks, but does not remove them from their scope's interceptors array. This seems similar to #721 but related to scope.interceptors rather than nock.pendingMocks().

Repro:

const nock = require('nock')
const scope = nock('http://example.com').get('/').reply(200)
console.log('interceptor count in scope:', scope.interceptors.length)
nock.removeInterceptor(scope.interceptors[0])
console.log('interceptor count in scope:', scope.interceptors.length)

Expected logged values:

interceptor count in scope: 1
interceptor count in scope: 0

Actual logged values:

interceptor count in scope: 1
interceptor count in scope: 1

Would you be interested in contributing a fix?

  • yes

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions