Skip to content
Browse files

Client emit request event and corresponding test

  • Loading branch information...
1 parent 235deab commit 7be19f82efbe6f49d1edbda3c086073010cb64f0 @tedeh committed Sep 21, 2012
Showing with 16 additions and 0 deletions.
  1. +2 −0 lib/client.js
  2. +14 −0 test/client.test.js
View
2 lib/client.js
@@ -86,6 +86,8 @@ Client.prototype.request = function(method, params, id, callback) {
if(!hasCallback) return request;
}
+ this.emit('request', request);
+
this._request(request, function(err, response) {
if(err) return callback(err);
View
14 test/client.test.js
@@ -66,6 +66,20 @@ describe('jayson client instance', function() {
});
});
+ it('should emit request just as the request is dispatched', function(done) {
+ var a = 6, b = 9, hasFired = false;
+ client.once('request', function(request) {
+ hasFired = true;
+ should.exist(request);
+ request.params.should.include(6).and.include(9).and.have.lengthOf(2);
+ });
+ client.request('add', [a, b], function(err) {
+ if(err) return done(err);
+ hasFired.should.be.ok;
+ done();
+ });
+ });
+
it('should be able to execute a notification request', function(done) {
var a = 3, b = 4;
client.request('add', [a, b], null, function(err, response) {

0 comments on commit 7be19f8

Please sign in to comment.
Something went wrong with that request. Please try again.