e8f79d43f9
closes #517 add index test for Application add app.toJSON test add test for app.inspect() add tests for app.use() add tests for app.onerror() add tests for app.respond() add tests for app.context() add tests for app.request() add tests for app.response refactor for non-existence of test/app...js no need for *.js use helpers/ dir for non-tests
57 lines
1.1 KiB
JavaScript
57 lines
1.1 KiB
JavaScript
|
|
'use strict';
|
|
|
|
const request = require('supertest');
|
|
const koa = require('../..');
|
|
|
|
describe('app.use(fn)', function(){
|
|
it('should compose middleware', function(done){
|
|
const app = koa();
|
|
const calls = [];
|
|
|
|
app.use(function *(next){
|
|
calls.push(1);
|
|
yield next;
|
|
calls.push(6);
|
|
});
|
|
|
|
app.use(function *(next){
|
|
calls.push(2);
|
|
yield next;
|
|
calls.push(5);
|
|
});
|
|
|
|
app.use(function *(next){
|
|
calls.push(3);
|
|
yield next;
|
|
calls.push(4);
|
|
});
|
|
|
|
const server = app.listen();
|
|
|
|
request(server)
|
|
.get('/')
|
|
.expect(404)
|
|
.end(function(err){
|
|
if (err) return done(err);
|
|
calls.should.eql([1,2,3,4,5,6]);
|
|
done();
|
|
});
|
|
})
|
|
|
|
it('should error when a non-generator function is passed', function(){
|
|
const app = koa();
|
|
|
|
try {
|
|
app.use(function(){});
|
|
} catch (err) {
|
|
err.message.should.equal('app.use() requires a generator function');
|
|
}
|
|
})
|
|
|
|
it('should not error when a non-generator function is passed when .experimental=true', function(){
|
|
const app = koa();
|
|
app.experimental = true;
|
|
app.use(function(){});
|
|
})
|
|
})
|