[Pkg-javascript-commits] [node-mocks-http] 55/296: Increment version number

Thorsten Alteholz alteholz at moszumanska.debian.org
Mon Feb 8 18:13:20 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 fcc989c407380e0fbf92d0aa11fe383fe8ca8478
Author: Howard Abrams <howard.abrams at gmail.com>
Date:   Fri Oct 17 22:27:36 2014 -0700

    Increment version number
    
    To publish change for patch #23, incremented the version to 1.2.1
    
    Also re-factored the function to be more straight-forward with some
    better documentation.
---
 README.md           | 28 +++++++++++++++-----------
 lib/mockResponse.js | 57 +++++++++++++++++++++++++----------------------------
 package.json        |  2 +-
 3 files changed, 45 insertions(+), 42 deletions(-)

diff --git a/README.md b/README.md
index 9c2da8b..05e5908 100644
--- a/README.md
+++ b/README.md
@@ -1,14 +1,16 @@
 node-mocks-http
 ---
 
-Mock 'http' objects for testing [Express](http://expressjs.com/) routing functions, but could be used
-for testing any [Node.js](http://www.nodejs.org) web server applications that
-have code that requires mockups of the `request` and `response` objects.
+Mock 'http' objects for testing [Express](http://expressjs.com/)
+routing functions, but could be used for testing any
+[Node.js](http://www.nodejs.org) web server applications that have
+code that requires mockups of the `request` and `response` objects.
 
 Installation
 ---
 
-This project is available as a [NPM package](https://www.npmjs.org/package/node-mocks-http).
+This project is available as a
+[NPM package](https://www.npmjs.org/package/node-mocks-http).
 
 ```bash
 $ npm install node-mocks-http
@@ -35,7 +37,8 @@ And you have created a function to handle that route's call:
 var routeHandler = function( request, response ) { ... };
 ```
 
-You can easily test the `routeHandler` function with some code like this using the testing framework of your choice:
+You can easily test the `routeHandler` function with some code like
+this using the testing framework of your choice:
 
 ```js
 exports['routeHandler - Simple testing'] = function(test) {
@@ -72,14 +75,16 @@ Design Decisions
 
 We wanted some simple mocks without a large framework.
 
-We also wanted the mocks to act like the original framework being mocked,
-but allow for setting of values before calling and inspecting of values after calling.
+We also wanted the mocks to act like the original framework being
+mocked, but allow for setting of values before calling and inspecting
+of values after calling.
 
 For Developers
 ---
 
-We are looking for more volunteers to bring value to this project, including the
-creation of more objects from the [HTTP module](http://nodejs.org/docs/latest/api/http.html).
+We are looking for more volunteers to bring value to this project,
+including the creation of more objects from the
+[HTTP module](http://nodejs.org/docs/latest/api/http.html).
 
 This project doesn't address all features that must be
 mocked, but it is a good start. Feel free to send pull requests,
@@ -96,7 +101,8 @@ Install `jshint` globally.
 npm install -g jshint
 ```
 
-Navigate to the project folder and run `npm install` to install the project's dependencies.
+Navigate to the project folder and run `npm install` to install the
+project's dependencies.
 
 Then simply run the tests.
 
@@ -115,4 +121,4 @@ by Express.
 License
 ---
 
-Licensed under [MIT](https://github.com/howardabrams/node-mocks-http/blob/master/LICENSE).
\ No newline at end of file
+Licensed under [MIT](https://github.com/howardabrams/node-mocks-http/blob/master/LICENSE).
diff --git a/lib/mockResponse.js b/lib/mockResponse.js
index 43e661f..6b3b727 100644
--- a/lib/mockResponse.js
+++ b/lib/mockResponse.js
@@ -178,41 +178,38 @@ function createResponse(options) {
     };
 
     /**
-     *  The 'json' function from node's HTTP API that returns JSON data
-     *  to the client.  Should not be called multiple times.
+     * Function: json
+     *
+     *   The 'json' function from node's HTTP API that returns JSON
+     *   data to the client.
+     *
+     *  Parameters:
+     *
+     *   a - Either a statusCode or string containing JSON payload
+     *   b - Either a statusCode or string containing JSON payload
+     *
+     *  If not specified, the statusCode defaults to 200.
+     *  Second parameter is optional.
      */
     mockResponse.json = function(a, b) {
 
         mockResponse.setHeader('Content-Type', 'application/json');
+        mockResponse.statusCode = 200;
 
-        switch (arguments.length) {
-
-            case 1:
-
-                if (typeof a === 'number') {
-                    mockResponse.statusCode = a;
-                } else {
-                    _data += JSON.stringify(a);
-                    mockResponse.statusCode = 200;
-                }
-
-                break;
-
-            case 2:
-                if(typeof a === 'number'){
-                    this.statusCode = a;
-                    _data += JSON.stringify(b);
-                } else {
-                    this.statusCode = b;
-                    _data += JSON.stringify(a);
-                }
-
-                break;
-
-            default:
-                break;
+        if (a) {
+            if (typeof a === 'number') {
+                mockResponse.statusCode = a;
+            } else {
+                _data += JSON.stringify(a);
+            }
+        }
+        if (b) {
+            if (typeof b === 'number') {
+                mockResponse.statusCode = b;
+            } else {
+                _data += JSON.stringify(b);
+            }
         }
-
     };
 
     /**
@@ -567,4 +564,4 @@ function createResponse(options) {
 
 }
 
-module.exports.createResponse = createResponse;
\ No newline at end of file
+module.exports.createResponse = createResponse;
diff --git a/package.json b/package.json
index c978a95..308cac7 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": "1.2.0",
+  "version": "1.2.1",
   "homepage": "http://www.github.com/howardabrams/node-mocks-http",
   "license" : "MIT",
   "keywords": [

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