Skip to content

Commit

Permalink
test: modify for es6 class
Browse files Browse the repository at this point in the history
  • Loading branch information
magicdawn committed Jul 16, 2016
1 parent 6077536 commit 2f96823
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
12 changes: 1 addition & 11 deletions test/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
8 changes: 4 additions & 4 deletions test/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -44,7 +44,7 @@ describe('Route', function() {
return r.dispatch(ctx, next);
});
app = app.callback();

request(app)
.delete('/foo')
.expect(404, done);
Expand Down
17 changes: 7 additions & 10 deletions test/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 2f96823

Please sign in to comment.