Browse Source

Bring back tests for custom errors

master
Leo Lamprecht 8 years ago
parent
commit
c296cfb789
No known key found for this signature in database GPG Key ID: B08517883D5E0E10
  1. 40
      test/index.js

40
test/index.js

@ -216,6 +216,46 @@ test('send(200, <Stream>) with error on same tick', async t => {
} }
}) })
test('custom error', async t => {
const fn = () => {
sleep(50)
throw new Error('500 from test (expected)')
}
const handleErrors = fn => (req, res) => {
try {
return fn(req, res)
} catch (err) {
send(res, 200, 'My custom error!')
}
}
const url = await listen(handleErrors(fn))
const res = await request(url)
t.deepEqual(res, 'My custom error!')
})
test('custom async error', async t => {
const fn = async () => {
sleep(50)
throw new Error('500 from test (expected)')
}
const handleErrors = fn => async (req, res) => {
try {
return await fn(req, res)
} catch (err) {
send(res, 200, 'My custom error!')
}
}
const url = await listen(handleErrors(fn))
const res = await request(url)
t.deepEqual(res, 'My custom error!')
})
test('json parse error', async t => { test('json parse error', async t => {
const fn = async (req, res) => { const fn = async (req, res) => {
const body = await json(req) const body = await json(req)

Loading…
Cancel
Save