Last active
July 23, 2017 07:26
-
-
Save koresar/65fcda7ee678689083ea8bd8547b6b13 to your computer and use it in GitHub Desktop.
Fun with Stamps. Episode 17. Easy 100% unit test coverage in JS: - app2-test2.js
This file contains hidden or 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
describe('routing', () => { | |
const App = require('../app2'); | |
const {handleNotFound, handleGenericError} = App.compose.methods; | |
it('should set status code to 404 when no route found', (done) => { | |
handleNotFound({}, {}, (error) => { | |
if (!error || error.status !== 404) { | |
throw new Error('Error status should be 404'); | |
} | |
done(); | |
}); | |
}); | |
it('should not share error details in responses', () => { | |
const req = {app: {get() { return 'production'; }}}; | |
const res = {locals: {}, status() {}, render() {}}; | |
handleGenericError(new Error('my unexpected error'), req, res); | |
if (res.locals.error instanceof Error) { | |
throw Error('Error details were shared in "production" env'); | |
} | |
}); | |
it('should share error message in responses', () => { | |
const req = {app: {get() { return 'production'; }}}; | |
const res = {locals: {}, status() {}, render() {}}; | |
handleGenericError(new Error('my unexpected error'), req, res); | |
if (res.locals.message !== 'my unexpected error') { | |
throw Error('Error message should be shared in "production" env'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment