koa-lite/test/babel/_test.js

43 lines
888 B
JavaScript
Raw Normal View History

2015-11-04 19:15:18 +00:00
'use strict';
const request = require('supertest');
const Koa = require('../..');
describe('require("babel-core/register")', () => {
describe('app.use(fn)', () => {
it('should compose middleware w/ async functions', done => {
const app = new Koa();
const calls = [];
app.use(async (ctx, next) => {
2015-11-04 19:15:18 +00:00
calls.push(1);
await next();
calls.push(6);
});
app.use(async (ctx, next) => {
2015-11-04 19:15:18 +00:00
calls.push(2);
await next();
calls.push(5);
});
app.use(async (ctx, next) => {
2015-11-04 19:15:18 +00:00
calls.push(3);
await next();
calls.push(4);
});
const server = app.listen();
request(server)
.get('/')
.expect(404)
.end(err => {
if (err) return done(err);
calls.should.eql([1, 2, 3, 4, 5, 6]);
done();
});
});
});
});