Permalink
Browse files

Cleaned up to pass JSHint

  • Loading branch information...
1 parent 80d9fdf commit 0df9b3557edf459a4297dd22a806b976d1048857 @diachedelic diachedelic committed Dec 13, 2013
Showing with 639 additions and 603 deletions.
  1. +20 −0 .jshintrc
  2. +39 −35 examples/express-route.js
  3. +11 −11 lib/mockEventEmitter.js
  4. +155 −153 lib/mockRequest.js
  5. +407 −397 lib/mockResponse.js
  6. +7 −7 lib/mockWritableStream.js
View
@@ -0,0 +1,20 @@
+{
+ "node": true,
+ "esnext": true,
+ "bitwise": true,
+ "camelcase": true,
+ "curly": true,
+ "eqeqeq": true,
+ "immed": true,
+ "indent": 2,
+ "latedef": true,
+ "newcap": true,
+ "noarg": true,
+ "quotmark": "single",
+ "regexp": true,
+ "undef": true,
+ "unused": false,
+ "strict": true,
+ "trailing": true,
+ "smarttabs": true
+}
@@ -1,3 +1,5 @@
+'use strict';
+
var httpMocks = require('../lib/http-mock');
// Suppose we have the following magical Express incantation:
@@ -6,44 +8,46 @@ var httpMocks = require('../lib/http-mock');
//
// And we have ourselves a function to answer that call:
-var aroute = function( request, response ) {
-
- var id = request.params.id;
- console.log("We have a '%s' request for %s (ID: %d)",
- request.method, request.url, id);
-
- var body = {
- name: 'Bob Dog',
- age: 42,
- email: 'bob@dog.com'
- };
- response.setHeader('Content-Type', 'application/json');
- response.statusCode = 200;
- response.send( JSON.stringify(body), 'utf8' );
- response.end();
+var aroute = function (request, response) {
+
+ var id = request.params.id;
+ console.log('We have a \'%s\' request for %s (ID: %d)',
+ request.method, request.url, id);
+
+ var body = {
+ name: 'Bob Dog',
+ age: 42,
+ email: 'bob@dog.com'
+ };
+ response.setHeader('Content-Type', 'application/json');
+ response.statusCode = 200;
+ response.send(JSON.stringify(body), 'utf8');
+ response.end();
};
// -----------------------------------------------------------------
// In another file, we can now test that function, like so:
-exports['aroute - Simple testing'] = function(test) {
- var request = httpMocks.createRequest({
- method: 'GET',
- url: '/user/42',
- params: { id: 42 }
- });
- var response = httpMocks.createResponse();
-
- aroute(request, response);
-
- var data = JSON.parse( response._getData() );
- test.equal("Bob Dog", data.name);
- test.equal(42, data.age);
- test.equal("bob@dog.com", data.email);
-
- test.equal(200, response.statusCode );
- test.ok( response._isEndCalled());
- test.ok( response._isJSON());
- test.ok( response._isUTF8());
- test.done();
+exports['aroute - Simple testing'] = function (test) {
+ var request = httpMocks.createRequest({
+ method: 'GET',
+ url: '/user/42',
+ params: {
+ id: 42
+ }
+ });
+ var response = httpMocks.createResponse();
+
+ aroute(request, response);
+
+ var data = JSON.parse(response._getData());
+ test.equal('Bob Dog', data.name);
+ test.equal(42, data.age);
+ test.equal('bob@dog.com', data.email);
+
+ test.equal(200, response.statusCode);
+ test.ok(response._isEndCalled());
+ test.ok(response._isJSON());
+ test.ok(response._isUTF8());
+ test.done();
};
@@ -1,18 +1,18 @@
/*
* http://nodejs.org/api/events.html
-*/
+ */
-function EventEmitter(){}
+function EventEmitter() {}
-EventEmitter.prototype.addListener = function(event, listener){}
-EventEmitter.prototype.on = function(event, listener){}
-EventEmitter.prototype.once = function(event, listener){}
-EventEmitter.prototype.removeListener = function(event, listener){}
-EventEmitter.prototype.removeAllListeners = function(event){}
+EventEmitter.prototype.addListener = function (event, listener) {};
+EventEmitter.prototype.on = function (event, listener) {};
+EventEmitter.prototype.once = function (event, listener) {};
+EventEmitter.prototype.removeListener = function (event, listener) {};
+EventEmitter.prototype.removeAllListeners = function (event) {};
// EventEmitter.prototype.removeAllListeners = function([event])
-EventEmitter.prototype.setMaxListeners = function(n){}
-EventEmitter.prototype.listeners = function(event){}
-EventEmitter.prototype.emit = function(event){}
+EventEmitter.prototype.setMaxListeners = function (n) {};
+EventEmitter.prototype.listeners = function (event) {};
+EventEmitter.prototype.emit = function (event) {};
// EventEmitter.prototype.emit = function(event, [arg1], [arg2], [...]){}
-module.exports = EventEmitter;
+module.exports = EventEmitter;
Oops, something went wrong. Retry.

0 comments on commit 0df9b35

Please sign in to comment.