[Pkg-javascript-commits] [node-mocks-http] 31/296: Passed json() tests

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 419cc1790bf8ef9a3392d02e1e18b3226ea90b0e
Author: James Diacono <james at diacono.com.au>
Date:   Fri Dec 13 16:24:05 2013 +1100

    Passed json() tests
---
 lib/mockResponse.js | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/lib/mockResponse.js b/lib/mockResponse.js
index f9011b5..7fa78bd 100644
--- a/lib/mockResponse.js
+++ b/lib/mockResponse.js
@@ -140,6 +140,33 @@ exports.createResponse = function (options) {
       }
     },
 
+    /**
+     *  The 'json' function from node's HTTP API that returns JSON data
+     *  to the client.  Should not be called multiple times.
+     */
+    json: function (a, b) {
+      this.setHeader('Content-Type', 'application/json');
+
+      switch (arguments.length) {
+      case 1:
+        if (typeof a === 'number') {
+          this.statusCode = a;
+        } else {
+          _data += JSON.stringify(a);
+          this.statusCode = 200;
+        }
+        break;
+
+      case 2:
+        this.statusCode = a;
+        _data += JSON.stringify(b);
+
+        break;
+
+      default:
+        break;
+      }
+    },
 
     /**
      * Function: write

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