Skip to content

Commit

Permalink
Remove pending mocks from scopes on nock.cleanAll()
Browse files Browse the repository at this point in the history
  • Loading branch information
mathewjoe committed Mar 19, 2017
1 parent c5f265f commit f45f574
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/intercept.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ function remove(interceptor) {
}

function removeAll() {
Object.keys(allInterceptors).forEach(function(key) {
allInterceptors[key].scopes.forEach(function(interceptor) {
interceptor.scope.keyedInterceptors = {};
});
});
allInterceptors = {};
}

Expand Down
17 changes: 17 additions & 0 deletions tests/test_intercept.js
Original file line number Diff line number Diff line change
Expand Up @@ -2249,6 +2249,23 @@ test('clean all works', function(t) {

});

test('clean all should remove pending mocks from all scopes', function(t) {
var scope1 = nock('http://example.org')
.get('/somepath')
.reply(200, 'hey');
t.deepEqual(scope1.pendingMocks(), ['GET http://example.org:80/somepath']);
var scope2 = nock('http://example.com')
.get('/somepath')
.reply(200, 'hey');
t.deepEqual(scope2.pendingMocks(), ['GET http://example.com:80/somepath']);

nock.cleanAll();

t.deepEqual(scope1.pendingMocks(), []);
t.deepEqual(scope2.pendingMocks(), []);
t.end();
});

test('is done works', function(t) {
var scope = nock('http://amazon.com')
.get('/nonexistent')
Expand Down

0 comments on commit f45f574

Please sign in to comment.