Skip to content

Instantly share code, notes, and snippets.

@kid
Last active May 4, 2016 09:45
Show Gist options
  • Save kid/ee9b6790a34537c9ed34ec4daeb1803f to your computer and use it in GitHub Desktop.
Save kid/ee9b6790a34537c9ed34ec4daeb1803f to your computer and use it in GitHub Desktop.
import Hapi from 'hapi'
const routeWithErrorInPromise = {
method: 'GET',
path: '/foo',
handler: (request, reply) => {
return reply(Promise.resolve('foo').then(() => { throw new Error('foo') }))
}
}
describe('(Hapi) inject()', () => {
it('should catch errors in promises', () => {
const server = new Hapi.Server()
server.connection({})
let _error
server.on('request-internal', (_, event, tags) => {
if (tags.error && tags.internal) {
_error = event.data
}
})
server.route(routeWithErrorInPromise)
return server.inject('/foo').then((response) => {
expect(_error).to.be.ok
expect(response.statusCode).to.equal(500)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment