Permalink
Browse files

Passed json() tests

  • Loading branch information...
diachedelic committed Dec 13, 2013
1 parent 0173d8f commit 419cc1790bf8ef9a3392d02e1e18b3226ea90b0e
Showing with 27 additions and 0 deletions.
  1. +27 −0 lib/mockResponse.js
View
@@ -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

0 comments on commit 419cc17

Please sign in to comment.