From c43477eb0484c328d9734ad1809a4a2ff18615d3 Mon Sep 17 00:00:00 2001 From: simov Date: Fri, 27 Mar 2015 10:34:38 +0200 Subject: [PATCH] Allow static invoking of convenience methods --- index.js | 2 +- tests/test-defaults.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index f8b35150e..45bba9eee 100755 --- a/index.js +++ b/index.js @@ -61,7 +61,7 @@ verbs.forEach(function(verb){ request[verb] = function(uri, options, callback){ var params = initParams(uri, options, callback) params.options.method = method - return this(params.uri || null, params.options, params.callback) + return (this || request)(params.uri || null, params.options, params.callback) } }) diff --git a/tests/test-defaults.js b/tests/test-defaults.js index 09131a172..f00ee3cdc 100644 --- a/tests/test-defaults.js +++ b/tests/test-defaults.js @@ -105,6 +105,11 @@ tape('setup', function(t) { }) }) + s.on('/function', function(req, resp) { + resp.writeHead(200, {'Content-Type': 'text/plain'}) + resp.end() + }) + t.end() }) }) @@ -299,6 +304,16 @@ tape('test only setting undefined properties', function(t) { }) }) +tape('test only function', function(t) { + var post = request.post + t.doesNotThrow(function () { + post(s.url + '/function', function (e, r, b) { + t.equal(r.statusCode, 200) + t.end() + }) + }) +}) + tape('cleanup', function(t) { s.close(function() { t.end()