Skip to content

Instantly share code, notes, and snippets.

@avik-so
Last active January 22, 2017 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avik-so/f7a3c09fd6e3236fe9dcdf5ad9006ab4 to your computer and use it in GitHub Desktop.
Save avik-so/f7a3c09fd6e3236fe9dcdf5ad9006ab4 to your computer and use it in GitHub Desktop.
Unit Test:
describe('check unhandled exceptions', () => {
it ('should log error and exit if unhandled exception is caught', ()=> {
let options = {
log: console.log,
err: console.error };
let errSpy = sinon.spy(options, 'err');
let expOut = "Server has crashed with Error: We Crashed!";
app.crash();
expect( errSpy.calledWith(expOut) ).to.be.true;
})
});
Output:
1 failing
1) check unhandled exceptions should log error and exit if unhandled exception is caught:
Error: We Crashed!
at APP.crash (lib\src\app.ts:48:15)
at Context.it (lib\specs\app.spec.ts:87:9)
Code:
export class APP {
constructor() {
process.on('uncaughtException', err => {
console.error("Server has crashed with ", err);
process.exit(1);
});
}
crash(){
throw new Error("We Crashed!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment