Skip to content

Update PendingMocks when an interceptor is removed#721

Merged
vrinek merged 1 commit into
nock:masterfrom
pimterry:removeInterceptor-from-pending
Oct 16, 2016
Merged

Update PendingMocks when an interceptor is removed#721
vrinek merged 1 commit into
nock:masterfrom
pimterry:removeInterceptor-from-pending

Conversation

@pimterry

Copy link
Copy Markdown
Contributor

Currently when you call nock.removeInterceptor(interceptor) it stops that interceptor from doing any more intercepting, but doesn't remove it from pendingMocks() (this is part of #600).

This fixes that, by updating the interceptor's scope to remove it properly. I.e. with this change, pendingMocks is now empty at the end, as expected:

var interceptor = nock('http://example.org').get('/somepath');
var scope = interceptor.reply(200, 'hey');

nock.removeInterceptor(interceptor);

scope.pendingMocks() // Empty;

It looks like there's a separate issue in #600 that I haven't looked at about how nock.pendingMocks() behaves with scope reuse. This patch doesn't fix that (and I'm probably not going to, since it doesn't affect me).

This patch also includes an unrelated change to remove replyWithFile from browserify-bundle. Not really sure why, but I'd guess this means somebody else made that change in lib/ recently and forgot to commit the corresponding browserify-bundle.

@coveralls

coveralls commented Oct 12, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.009%) to 96.551% when pulling d6dc97d on pimterry:removeInterceptor-from-pending into bc565eb on node-nock:master.

@vrinek

vrinek commented Oct 16, 2016

Copy link
Copy Markdown
Contributor

Code looks good. Thanks for the contribution!

@vrinek vrinek merged commit 5af77f0 into nock:master Oct 16, 2016
@vrinek

vrinek commented Oct 23, 2016

Copy link
Copy Markdown
Contributor

Published as part of v8.2.0 🎉

@c0bra

c0bra commented Feb 24, 2017

Copy link
Copy Markdown

Seems like I'm still seeing this as of v9.0.6.

console.log('pending mocks 1', nock.pendingMocks());
console.log('removing mock');
nock.removeInterceptor(this.nock);
console.log('pending mocks 2', nock.pendingMocks());

The second dump of pendingMocks() is identical to the first. this.nock is an Interceptor instance that was created in a mocha beforeEach. The removeInterceptor() is being called in an afterEach.

Update

My mistake. I was storing the result of reply() in this.nock, which would be a Scope and not an interceptor. I needed to save the result of the call above reply (in this case it was a post()). All is working, thanks!

@pimterry pimterry deleted the removeInterceptor-from-pending branch March 28, 2017 12:18
@lock

lock Bot commented Sep 13, 2018

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!

@lock lock Bot locked as resolved and limited conversation to collaborators Sep 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants