Last active
May 4, 2016 09:45
-
-
Save kid/ee9b6790a34537c9ed34ec4daeb1803f to your computer and use it in GitHub Desktop.
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
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