From c2de880a8ad0345d9da21e856c5d60969085dbcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fran=C3=A7a?= Date: Sun, 5 Feb 2012 22:20:01 -0200 Subject: [PATCH] fix when callback is not specified in http request --- lib/recorder.js | 4 +++- tests/test_recorder.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/recorder.js b/lib/recorder.js index 6bf851396..dcfe73815 100644 --- a/lib/recorder.js +++ b/lib/recorder.js @@ -61,7 +61,9 @@ function record(dont_print) { if (! dont_print) { console.log(SEPARATOR + out + SEPARATOR); } }); - callback.apply(res, arguments); + if (callback) { + callback.apply(res, arguments); + } }); oldWrite = req.write; diff --git a/tests/test_recorder.js b/tests/test_recorder.js index 3af3c7627..d12ebbdb5 100644 --- a/tests/test_recorder.js +++ b/tests/test_recorder.js @@ -26,4 +26,16 @@ tap.test('records', function(t) { req.write('ABCDEF'); req.end(); return req; +}); + +tap.test('checks if callback is specified', function(t) { + var options = { + host: 'www.google.com', method: 'GET', path: '/', port: 80 + }; + + nock.restore(); + nock.recorder.rec(true); + + http.request(options, undefined).end(); + t.end(); }); \ No newline at end of file