From 2f968234e2c330905587419e2e4334d462074679 Mon Sep 17 00:00:00 2001 From: "magicdawn@qq.com" Date: Sat, 16 Jul 2016 21:59:28 +0800 Subject: [PATCH] test: modify for es6 class --- test/layer.js | 12 +----------- test/route.js | 8 ++++---- test/router.js | 17 +++++++---------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/test/layer.js b/test/layer.js index e4203b7..fec1072 100644 --- a/test/layer.js +++ b/test/layer.js @@ -7,18 +7,8 @@ const METHODS = require('methods'); const Layer = require('../lib/layer'); describe('Layer', function() { - it('construct without new', function() { - const l = Layer('/foo', { - end: true - }, (ctx) => { - ctx.body = 'foo'; - }); - - l.should.be.ok; - }); - it('#match(path) return false when path is empty', function() { - const l = Layer('/foo', { + const l = new Layer('/foo', { end: true }, (ctx, next) => { ctx.body = 'foo'; diff --git a/test/route.js b/test/route.js index 210a9fa..f15f021 100644 --- a/test/route.js +++ b/test/route.js @@ -13,11 +13,11 @@ describe('Route', function() { }); it('construct without new', function() { - Route('/').should.be.ok; + (new Route('/')).should.be.ok; }); it('play with route', function(done) { - const r = Route('/foo'); + const r = new Route('/foo'); app.use((ctx, next) => { return r.dispatch(ctx, next); @@ -35,7 +35,7 @@ describe('Route', function() { ctx.body = ctx.method; }; - const r = Route('/foo') + const r = (new Route('/foo')) .get(fn) .post(fn) .put(fn); @@ -44,7 +44,7 @@ describe('Route', function() { return r.dispatch(ctx, next); }); app = app.callback(); - + request(app) .delete('/foo') .expect(404, done); diff --git a/test/router.js b/test/router.js index c519548..89efe17 100644 --- a/test/router.js +++ b/test/router.js @@ -12,22 +12,19 @@ describe('Router', function() { beforeEach(function() { app = new Koa(); - router = Router(); + router = new Router(); app.use(router); }); - it('ok with/without new', function() { + it('ok with new', function() { let router = new Router(); (typeof router).should.equal('function'); - - router = Router(); - (typeof router).should.equal('function'); }); it('nested router', function(done) { - const routerA = Router(); - const routerB = Router(); - const routerC = Router(); + const routerA = new Router(); + const routerB = new Router(); + const routerC = new Router(); router.use('/a', routerA); routerA.use('/b', routerB); @@ -58,7 +55,7 @@ describe('Router', function() { describe('params#', function() { it('default `mergeParams` = true', function(done) { - const userRouter = Router(); + const userRouter = new Router(); router.use('/user/:uid', userRouter); userRouter.get('/get_:field', function(ctx, next) { @@ -82,7 +79,7 @@ describe('Router', function() { }); it('set `mergeParams` to false', function(done) { - const userRouter = Router({ + const userRouter = new Router({ mergeParams: false }); router.use('/user/:uid', userRouter);