Skip to content

Commit

Permalink
Merge d6dc97d into bc565eb
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Oct 12, 2016
2 parents bc565eb + d6dc97d commit b969317
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
4 changes: 3 additions & 1 deletion lib/intercept.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ function removeInterceptor(options) {
if (allInterceptors[baseUrl] && allInterceptors[baseUrl].scopes.length > 0) {
if (key) {
for (var i = 0; i < allInterceptors[baseUrl].scopes.length; i++) {
if (allInterceptors[baseUrl].scopes[i]._key === key) {
var interceptor = allInterceptors[baseUrl].scopes[i];
if (interceptor._key === key) {
allInterceptors[baseUrl].scopes.splice(i, 1);
interceptor.scope.remove(key, interceptor);
break;
}
}
Expand Down
15 changes: 3 additions & 12 deletions tests/browserify-public/browserify-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,10 @@ function removeInterceptor(options) {
if (allInterceptors[baseUrl] && allInterceptors[baseUrl].scopes.length > 0) {
if (key) {
for (var i = 0; i < allInterceptors[baseUrl].scopes.length; i++) {
if (allInterceptors[baseUrl].scopes[i]._key === key) {
var interceptor = allInterceptors[baseUrl].scopes[i];
if (interceptor._key === key) {
allInterceptors[baseUrl].scopes.splice(i, 1);
interceptor.scope.remove(key, interceptor);
break;
}
}
Expand Down Expand Up @@ -1311,17 +1313,6 @@ Interceptor.prototype.replyWithFile = function replyWithFile(statusCode, filePat
return this.reply(statusCode, readStream, headers);
};

Interceptor.prototype.replyWithFile = function replyWithFile(statusCode, filePath, headers) {
if (! fs) {
throw new Error('No fs');
}
var readStream = fs.createReadStream(filePath);
readStream.pause();
this.filePath = filePath;
return this.reply(statusCode, readStream, headers);
};


// Also match request headers
// https://github.com/pgte/nock/issues/163
Interceptor.prototype.reqheaderMatches = function reqheaderMatches(options, key) {
Expand Down
18 changes: 18 additions & 0 deletions tests/test_intercept.js
Original file line number Diff line number Diff line change
Expand Up @@ -4325,6 +4325,24 @@ test('remove interceptor removes given interceptor', function(t) {
});


test('remove interceptor removes interceptor from pending requests', function(t) {
var givenInterceptor = nock('http://example.org')
.get('/somepath');
var scope = givenInterceptor
.reply(200, 'hey');

var mocks = scope.pendingMocks();
t.deepEqual(mocks, ['GET http://example.org:80/somepath']);

var result = nock.removeInterceptor(givenInterceptor);
t.ok(result, 'result should be true');

var mocksAfterRemove = scope.pendingMocks();
t.deepEqual(mocksAfterRemove, [ ]);
t.end();
});


test('remove interceptor removes given interceptor for https', function(t) {
var givenInterceptor = nock('https://example.org')
.get('/somepath');
Expand Down

0 comments on commit b969317

Please sign in to comment.