Skip to content

Commit

Permalink
test(extend): update .extend test
Browse files Browse the repository at this point in the history
  • Loading branch information
tunnckoCore committed Oct 19, 2016
1 parent ba30fdd commit ed6e271
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ KoaBetterRouter.prototype.extend = function extend (router) {
throw new TypeError('.extend: expect `router` to be instance of KoaBetterBody')
}
router.routes.forEach((route) => {
/* istanbul ignore next */
if (route.prefix !== this.options.prefix) {
route = utils.updatePrefix(this, this.options, route)
}
Expand Down
12 changes: 11 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,24 @@ test('should `.getRoutes` return `this.routes` array', function (done) {
test('should be able to `.extend` routers', function (done) {
let apiRouter = Router({ prefix: '/api' })
let usersRouter = Router()
let catsRouter = Router()

catsRouter.addRoute('GET /cats', (ctx, next) => {})

usersRouter.addRoute('GET /users', (ctx, next) => {})
usersRouter.addRoute('GET /api/users/new', (ctx, next) => {})

// this route is first, with index 0
apiRouter.addRoute('GET /foo/bar', (ctx, next) => {})

// adds cats to users
usersRouter.extend(catsRouter)

// appends other router routes
// to already exsting ones
apiRouter.extend(usersRouter)

test.strictEqual(apiRouter.routes.length, 3)
test.strictEqual(apiRouter.routes.length, 4)

test.strictEqual(apiRouter.routes[0].prefix, '/api')
test.strictEqual(apiRouter.routes[0].route, '/foo/bar')
Expand All @@ -323,6 +329,10 @@ test('should be able to `.extend` routers', function (done) {
test.strictEqual(apiRouter.routes[2].prefix, '/api')
test.strictEqual(apiRouter.routes[2].route, '/api/users/new') // !!
test.strictEqual(apiRouter.routes[2].path, '/api/api/users/new') // !!

test.strictEqual(apiRouter.routes[3].prefix, '/api')
test.strictEqual(apiRouter.routes[3].route, '/cats')
test.strictEqual(apiRouter.routes[3].path, '/api/cats')
done()
})

Expand Down

0 comments on commit ed6e271

Please sign in to comment.