Skip to content

Commit

Permalink
koajs#72 Try to find failing test case, unsuccessfully for now
Browse files Browse the repository at this point in the history
  • Loading branch information
DreadBoy committed May 6, 2020
1 parent 6827a40 commit 58638ed
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict'

var request = require('supertest')
var mount = require('..')
var Koa = require('koa')
require('should')

describe('when throwing custom error in mounted app', function () {
it('should keep same class', function (done) {
var a = new Koa()

a.use(async function (ctx, next) {
throw new CustomError(400)
})

var app = new Koa()
app.use(async function (ctx, next) {
try {
await next()
ctx.status = 200
} catch (e) {
ctx.body = e instanceof CustomError
ctx.status = e.status
}
})
app.use(mount(a))

request(app.listen())
.get('/')
.expect(400)
.expect('true')
.end(done)
})
})

class CustomError extends Error {
constructor (status, message) {
super(message)
this.status = status
Error.captureStackTrace(this, CustomError)
}
}

0 comments on commit 58638ed

Please sign in to comment.