Skip to content

Commit f45f574

Browse files
committed
Remove pending mocks from scopes on nock.cleanAll()
1 parent c5f265f commit f45f574

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/intercept.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ function remove(interceptor) {
123123
}
124124

125125
function removeAll() {
126+
Object.keys(allInterceptors).forEach(function(key) {
127+
allInterceptors[key].scopes.forEach(function(interceptor) {
128+
interceptor.scope.keyedInterceptors = {};
129+
});
130+
});
126131
allInterceptors = {};
127132
}
128133

tests/test_intercept.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2249,6 +2249,23 @@ test('clean all works', function(t) {
22492249

22502250
});
22512251

2252+
test('clean all should remove pending mocks from all scopes', function(t) {
2253+
var scope1 = nock('http://example.org')
2254+
.get('/somepath')
2255+
.reply(200, 'hey');
2256+
t.deepEqual(scope1.pendingMocks(), ['GET http://example.org:80/somepath']);
2257+
var scope2 = nock('http://example.com')
2258+
.get('/somepath')
2259+
.reply(200, 'hey');
2260+
t.deepEqual(scope2.pendingMocks(), ['GET http://example.com:80/somepath']);
2261+
2262+
nock.cleanAll();
2263+
2264+
t.deepEqual(scope1.pendingMocks(), []);
2265+
t.deepEqual(scope2.pendingMocks(), []);
2266+
t.end();
2267+
});
2268+
22522269
test('is done works', function(t) {
22532270
var scope = nock('http://amazon.com')
22542271
.get('/nonexistent')

0 commit comments

Comments
 (0)