Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Passed json() tests

  • Loading branch information...
commit 419cc1790bf8ef9a3392d02e1e18b3226ea90b0e 1 parent 0173d8f
@diachedelic diachedelic authored
Showing with 27 additions and 0 deletions.
  1. +27 −0 lib/mockResponse.js
View
27 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
Please sign in to comment.
Something went wrong with that request. Please try again.