[Pkg-javascript-commits] [node-mocks-http] 14/296: The response.send now takes 2 parameters.

Thorsten Alteholz alteholz at moszumanska.debian.org
Mon Feb 8 18:13:16 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 c94da4a4df60f7919fd526db00540f5dfb10d811
Author: Howard Abrams <howard at howardabrams.com>
Date:   Wed Feb 29 23:53:26 2012 -0800

    The response.send now takes 2 parameters.
    
    In version 3.0 of Express, the response.send() can take a status code
    and payload data (in that order). We now allow this. In version 2.X of
    Express, the order was reversed, so we flag calling this function as a
    warning.
---
 README.md           | 36 +++++++++++++++++++++++++++++++++++-
 lib/mockResponse.js | 26 +++++++++++++++-----------
 package.json        |  2 +-
 3 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/README.md b/README.md
index 3625d25..23d2de8 100644
--- a/README.md
+++ b/README.md
@@ -61,4 +61,38 @@ before calling and inspecting afterwards.
 
 We are looking for more volunteers to value to this project, including the
 creation of more objects from the [HTTP module](http://nodejs.org/docs/latest/api/http.html).
-  
\ No newline at end of file
+
+Release Notes
+=============
+
+Most releases fixes bugs with our mocks or add features similar to the
+actual `Request` and `Response` objects offered by Node.js and extended
+by Express.
+
+v 0.0.5
+-------
+
+  * Fixed a bug where `response.send()` can take two parameters, the
+    status code and the data to send.
+
+v 0.0.4
+-------
+
+  * Added a `request.session` that can be set during construction (or via
+    calling the `_setSessionVariable()` method, and read as an object.
+    
+v 0.0.3
+-------
+
+  * Added a `request.query` that can be set during construction and read
+    as an object.
+
+v 0.0.2
+-------
+
+  * Code refactoring of the `Response` mock.
+  
+v 0.0.1
+-------
+
+  * Initial code banged out one late night...
\ No newline at end of file
diff --git a/lib/mockResponse.js b/lib/mockResponse.js
index 40b572e..9d8f64e 100644
--- a/lib/mockResponse.js
+++ b/lib/mockResponse.js
@@ -37,6 +37,11 @@ exports.createResponse = function(options) {
     return {
         statusCode: -1,
 
+        status: function(code) {
+            statusCode = code;
+            return this;
+        },
+        
         /**
          * Function: writeHead
          *
@@ -67,22 +72,21 @@ exports.createResponse = function(options) {
         },
         
         /**
-         *  Function: send
-         *
          *  The 'send' function from node's HTTP API that returns data
          *  to the client. Can be called multiple times.
          * 
-         * Parameters:
-         *
-         *  data - The data to return. Must be a string. Appended to 
-         *         previous calls to data.
-         *  encoding - Optional encoding value.
+         * @param data The data to return. Must be a string.
          */
-        send: function( data, encoding ) {
-            _data += data;
-            if (encoding) {
-                _encoding = encoding;
+        send: function( data ) {
+            if (2 == arguments.length) {
+                this.statusCode = data;
+                data = arguments[1];
             }
+
+            if (typeof data != 'String') {
+                console.warn("Called 'send' with '%s': %s", typeof data, data); 
+            }
+            _data += data;
         },
         
         
diff --git a/package.json b/package.json
index b232468..68e00b1 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "author": "Howard Abrams <howard.abrams at gmail.com> (http://www.github.com/howardabrams)",
   "name": "node-mocks-http",
   "description": "Mock 'http' objects for testing Express routing functions",
-  "version": "0.0.4",
+  "version": "0.0.5",
   "homepage": "http://www.github.com/howardabrams/node-mocks-http",
   "keywords": [
                "mock",

-- 
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