|
1 | 1 | /* eslint no-shadow:0, consistent-return:0, no-console:0 */
|
| 2 | +/* global Promise */ |
2 | 3 | 'use strict';
|
3 | 4 |
|
4 | 5 | var raven = require('../'),
|
@@ -272,6 +273,51 @@ describe('raven.Client', function () {
|
272 | 273 | });
|
273 | 274 | });
|
274 | 275 |
|
| 276 | + describe('#install()', function () { |
| 277 | + beforeEach(function () { |
| 278 | + process.removeAllListeners('uncaughtException'); |
| 279 | + process.removeAllListeners('unhandledRejection'); |
| 280 | + }); |
| 281 | + |
| 282 | + afterEach(function () { |
| 283 | + process.removeAllListeners('uncaughtException'); |
| 284 | + process.removeAllListeners('unhandledRejection'); |
| 285 | + }); |
| 286 | + |
| 287 | + it('should not listen for unhandledRejection unless told to', function () { |
| 288 | + var listeners = process.listeners('unhandledRejection'); |
| 289 | + listeners.length.should.equal(0); |
| 290 | + |
| 291 | + client.install(); |
| 292 | + |
| 293 | + listeners = process.listeners('unhandledRejection'); |
| 294 | + listeners.length.should.equal(0); |
| 295 | + }); |
| 296 | + |
| 297 | + it('should catch an unhandledRejection', function (done) { |
| 298 | + var listeners = process.listeners('unhandledRejection'); |
| 299 | + listeners.length.should.equal(0); |
| 300 | + |
| 301 | + client.install({ unhandledRejection: true }, function (sent, reason) { |
| 302 | + reason.message.should.equal('rejected!'); |
| 303 | + done(); |
| 304 | + }); |
| 305 | + |
| 306 | + listeners = process.listeners('unhandledRejection'); |
| 307 | + listeners.length.should.equal(1); |
| 308 | + |
| 309 | + // promises didn't fire unhandledRejection until 1.4.1 |
| 310 | + if (process.version >= 'v1.4.1') { |
| 311 | + // eslint-disable-next-line no-new |
| 312 | + new Promise(function (resolve, reject) { |
| 313 | + reject(new Error('rejected!')); |
| 314 | + }); |
| 315 | + } else { |
| 316 | + process.emit('unhandledRejection', new Error('rejected!')); |
| 317 | + } |
| 318 | + }); |
| 319 | + }); |
| 320 | + |
275 | 321 | describe('#patchGlobal()', function () {
|
276 | 322 | beforeEach(function () {
|
277 | 323 | // remove existing uncaughtException handlers
|
|
0 commit comments