Skip to content

Commit 786970f

Browse files
committed
Add test that callback fires after sending/receiving response
1 parent b3f3eee commit 786970f

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lib/client.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ extend(Raven.prototype, {
8080
process: function process(eventId, kwargs, cb) {
8181
// prod codepaths shouldn't hit this branch, for testing
8282
if (typeof eventId === 'object') {
83+
cb = kwargs;
8384
kwargs = eventId;
8485
eventId = this.generateEventId();
8586
}

test/raven.client.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,36 @@ describe('raven.Client', function () {
382382
});
383383
});
384384

385+
it('should call the callback after sending', function (done) {
386+
var firedCallback = false;
387+
var sentResponse = false;
388+
var scope = nock('https://app.getsentry.com')
389+
.filteringRequestBody(/.*/, '*')
390+
.post('/api/269/store/', '*')
391+
.delay(10)
392+
.reply(200, function (uri, body) {
393+
zlib.inflate(new Buffer(body, 'base64'), function (err, dec) {
394+
if (err) return done(err);
395+
var msg = JSON.parse(dec.toString());
396+
msg.message.should.equal('test');
397+
});
398+
firedCallback.should.equal(false);
399+
sentResponse = true;
400+
return 'OK';
401+
});
402+
403+
client = new raven.Client(dsn);
404+
405+
client.process({
406+
message: 'test',
407+
}, function () {
408+
firedCallback = true;
409+
sentResponse.should.equal(true);
410+
scope.done();
411+
done();
412+
});
413+
});
414+
385415
it('should attach environment', function (done) {
386416
client = new raven.Client(dsn, {
387417
environment: 'staging'

0 commit comments

Comments
 (0)