koa-lite/test/context/error.js
Jonathan Ong 7d9c6ba66c context: .error() -> .throw()
.error() still works for compatibility, but it will be removed in the
future. closes #94
2013-11-18 17:38:12 -08:00

44 lines
No EOL
869 B
JavaScript

var context = require('../context');
var assert = require('assert');
describe('ctx.throw(msg)', function(){
it('should set .status to 500', function(done){
var ctx = context();
try {
ctx.throw('boom');
} catch (err) {
assert(500 == err.status);
done();
}
})
})
describe('ctx.throw(msg, status)', function(){
it('should throw an error', function(done){
var ctx = context();
try {
ctx.throw('name required', 400);
} catch (err) {
assert('name required' == err.message);
assert(400 == err.status);
done();
}
})
})
describe('ctx.throw(status)', function(){
it('should throw an error', function(done){
var ctx = context();
try {
ctx.throw(400);
} catch (err) {
assert('Bad Request' == err.message);
assert(400 == err.status);
done();
}
})
})