Last active
January 22, 2017 12:02
-
-
Save avik-so/f7a3c09fd6e3236fe9dcdf5ad9006ab4 to your computer and use it in GitHub Desktop.
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
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