Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PendingMocks when an interceptor is removed #721

Merged
merged 1 commit into from
Oct 16, 2016

Conversation

pimterry
Copy link
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
Copy link

coveralls commented Oct 12, 2016

Coverage Status

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

@vrinek
Copy link
Contributor

vrinek commented Oct 16, 2016

Code looks good. Thanks for the contribution!

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

vrinek commented Oct 23, 2016

Published as part of v8.2.0 🎉

@c0bra
Copy link

c0bra commented Feb 24, 2017

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
Copy link

lock bot commented Sep 13, 2018

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