Skip to content

Commit

Permalink
Emitting send and end events at json call
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Molonosov authored and Johnny Estilles committed Jun 2, 2015
1 parent 6063772 commit ae6c785
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/mockResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ function createResponse(options) {
_data += JSON.stringify(b);
}
}

mockResponse.emit('send');
mockResponse.emit('end');

};

/**
Expand Down
18 changes: 18 additions & 0 deletions test/lib/mockResponse.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,27 @@ describe('mockResponse', function() {

// TODO: fix in 2.0; method should mimic Express Response.json()
describe('.json()', function() {
var response;

beforeEach(function() {
response = mockResponse.createResponse();
sinon.spy(response, 'emit');
});

afterEach(function() {
response.emit.restore();
response = null;
});

it('method should mimic Express Response.json()');

it('should emit send and end events', function() {
response.json({});
expect(response.emit).to.have.been.calledTwice;
expect(response.emit).to.have.been.calledWith('send');
expect(response.emit).to.have.been.calledWith('end');
});

});

// TODO: fix in 2.0; method should mimic Express Response.redirect()
Expand Down

0 comments on commit ae6c785

Please sign in to comment.