Skip to content

Instantly share code, notes, and snippets.

@koresar
Last active July 23, 2017 07:26
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 koresar/65fcda7ee678689083ea8bd8547b6b13 to your computer and use it in GitHub Desktop.
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
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