Skip to content

Commit

Permalink
Merge pull request #11 from invernizzie/master
Browse files Browse the repository at this point in the history
Add end, send and render events for async testing.
  • Loading branch information
howardabrams committed Mar 30, 2014
2 parents dd528cd + be573dd commit c768b88
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/mockResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ exports.createResponse = function (options) {
default:
break;
}

this.emit('send');
this.emit('end');
},

/**
Expand Down Expand Up @@ -207,6 +210,7 @@ exports.createResponse = function (options) {
if (encoding) {
_encoding = encoding;
}
this.emit('end');
},


Expand Down Expand Up @@ -293,6 +297,9 @@ exports.createResponse = function (options) {
default:
break;
}

this.emit('render');
this.emit('end');
},

writable: function () {
Expand Down
46 changes: 46 additions & 0 deletions test/test-mockResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

var httpMocks = require('../lib/http-mock');
var EventEmitter = require('events').EventEmitter;

exports['object - Simple verification'] = function (test) {
var response = httpMocks.createResponse();
Expand Down Expand Up @@ -269,4 +270,49 @@ exports['json - With status code'] = function (test) {
test.equal(response._getData(), JSON.stringify(data));
test.equal(response.statusCode, 201);
test.done();
};

exports['events - end'] = function (test) {
var response = httpMocks.createResponse({
eventEmitter: EventEmitter
});

response.on('end', function () {
test.ok(response._isEndCalled());
test.done();
});

response.end();
};

exports['events - send'] = function (test) {
var response = httpMocks.createResponse({
eventEmitter: EventEmitter
});

response.on('send', function () {
test.equal(response.statusCode, 200);
test.done();
});

response.send(200);
};

exports['events - render'] = function (test) {
var response = httpMocks.createResponse({
eventEmitter: EventEmitter
});
var view = 'index';
var data = {
'name': 'bob'
};
var callback = function () {};

response.on('render', function () {
test.equal(response._getRenderView(), view);
test.deepEqual(response._getRenderData(), data);
test.done();
});

response.render(view, data, callback);
};

0 comments on commit c768b88

Please sign in to comment.