[Pkg-javascript-commits] [node-mocks-http] 34/296: Add end, send and render events for async testing. Fixes howardabrams/node-mocks-http#6.

Thorsten Alteholz alteholz at moszumanska.debian.org
Mon Feb 8 18:13:18 UTC 2016


This is an automated email from the git hooks/post-receive script.

alteholz pushed a commit to branch master
in repository node-mocks-http.

commit eea8e94f336f38017b0b5603273891e2f7096e32
Author: Esteban <invernizzie at gmail.com>
Date:   Sat Mar 1 22:15:41 2014 -0300

    Add end, send and render events for async testing.  Fixes howardabrams/node-mocks-http#6.
---
 lib/mockResponse.js       |  7 +++++++
 test/test-mockResponse.js | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/lib/mockResponse.js b/lib/mockResponse.js
index 7fa78bd..025b082 100644
--- a/lib/mockResponse.js
+++ b/lib/mockResponse.js
@@ -138,6 +138,9 @@ exports.createResponse = function (options) {
       default:
         break;
       }
+
+      this.emit('send');
+      this.emit('end');
     },
 
     /**
@@ -207,6 +210,7 @@ exports.createResponse = function (options) {
       if (encoding) {
         _encoding = encoding;
       }
+      this.emit('end');
     },
 
 
@@ -293,6 +297,9 @@ exports.createResponse = function (options) {
       default:
         break;
       }
+
+      this.emit('render');
+      this.emit('end');
     },
 
     writable: function () {
diff --git a/test/test-mockResponse.js b/test/test-mockResponse.js
index bc9c6df..b05414b 100644
--- a/test/test-mockResponse.js
+++ b/test/test-mockResponse.js
@@ -269,4 +269,49 @@ exports['json - With status code'] = function (test) {
   test.equal(response._getData(), JSON.stringify(data));
   test.equal(response.statusCode, 201);
   test.done();
+};
+
+exports['events - end'] = function (test) {
+  var response = httpMocks.createResponse({
+    eventEmitter: require('events').EventEmitter
+  });
+
+  response.on('end', function () {
+    test.ok(response._isEndCalled());
+    test.done();
+  });
+
+  response.end();
+};
+
+exports['events - send'] = function (test) {
+  var response = httpMocks.createResponse({
+    eventEmitter: require('events').EventEmitter
+  });
+
+  response.on('send', function () {
+    test.equal(response.statusCode, 200);
+    test.done();
+  });
+
+  response.send(200);
+};
+
+exports['events - render'] = function (test) {
+  var response = httpMocks.createResponse({
+    eventEmitter: require('events').EventEmitter
+  });
+  var view = 'index';
+  var data = {
+    'name': 'bob'
+  };
+  var callback = function () {};
+
+  response.on('render', function () {
+    test.equal(response._getRenderView(), view);
+    test.deepEqual(response._getRenderData(), data);
+    test.done();
+  });
+
+  response.render(view, data, callback);
 };
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-mocks-http.git



More information about the Pkg-javascript-commits mailing list