Created
June 9, 2016 07:30
-
-
Save caligo-mentis/784c4ebe847d80b8fab2ff6e6f1b117f to your computer and use it in GitHub Desktop.
Test uncaught exception with mocha tests runner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var should = require('should'); | |
describe('uncaught exception', function() { | |
describe('with interception', function() { | |
var listeners; | |
beforeEach(function() { | |
listeners = process.listeners('uncaughtException'); | |
process.removeAllListeners('uncaughtException'); | |
}); | |
afterEach(function() { | |
listeners.forEach(function(listener) { | |
process.on('uncaughtException', listener); | |
}); | |
}); | |
it('should be handled', function(done) { | |
process.once('uncaughtException', function(err) { | |
should(err.message).eql('Unhandled'); | |
done(); | |
}); | |
setImmediate(function() { | |
throw new Error('Unhandled'); | |
}); | |
}); | |
}); | |
describe('without interception', function() { | |
// Would produce duplicated tests | |
it('should not be handled', function(done) { | |
process.once('uncaughtException', function(err) { | |
should(err.message).eql('Unhandled'); | |
done(); | |
}); | |
setImmediate(function() { | |
throw new Error('Unhandled'); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment