Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added nock.cleanAll

  • Loading branch information...
commit 2d6470aa52695e585ec2ff2e5ff3684ca569a4d7 1 parent c000231
@pgte authored
View
5 README.md
@@ -191,6 +191,11 @@ Example:
You can also call `isDone()`, which will return a boolean saying if all the expectations are met or not (instead of throwing an exception);
+## .cleanAll()
+
+You can cleanup all the prepared mocks (could be useful to cleanup some state after a failed test) like this:
+
+ nock.cleanAll();
# Logging
View
7 lib/intercept.js
@@ -33,6 +33,10 @@ function remove(interceptor) {
//if (! interceptors) { delete allInterceptors[hostKey]; }
}
+function removeAll() {
+ allInterceptors = {};
+}
+
function interceptorsFor(options) {
var basePath;
@@ -114,4 +118,5 @@ http.ClientRequest = OverridenClientRequest;
);
-module.exports = add;
+module.exports = add;
+module.exports.removeAll = removeAll;
View
7 lib/scope.js
@@ -260,4 +260,11 @@ function startScope(basePath, options) {
return scope;
}
+function cleanAll() {
+ globalIntercept.removeAll();
+ return module.exports;
+}
+
module.exports = startScope;
+
+module.exports.cleanAll = cleanAll;
View
17 tests/test_intercept.js
@@ -195,7 +195,6 @@ tap.test("match headers", function(t) {
});
res.on('end', function() {
- console.log('all done here');
scope.done();
t.end();
});
@@ -1099,7 +1098,6 @@ tap.test("allow unmocked option works", function(t) {
, path: "/"
, port: 80
}, function(res) {
- console.log(res.statusCode);
t.assert(res.statusCode < 400 && res.statusCode >= 200, 'GET Google Home page');
t.end();
}).end();
@@ -1141,4 +1139,19 @@ tap.test("default reply headers work", function(t) {
host: 'default.reply.headers.com'
, path: '/'
}, done).end();
+});
+
+tap.test('clean all works', function(t) {
+ var scope = nock('http://clean.all.coz')
+ .get('/')
+ .reply(200);
+
+ nock.cleanAll();
+
+ var req = http.get({host: 'clean.all.coz', path: '/'});
+ req.on('error', function(e) {
+ t.equal(e.code, 'ENOTFOUND');
+ t.end();
+ });
+ req.end()
});
Please sign in to comment.
Something went wrong with that request. Please try again.