|
|
|
@ -4,7 +4,7 @@ var NotFoundError = require('../lib/error').NotFound
|
|
|
|
|
|
|
|
|
|
describe('Router', function () {
|
|
|
|
|
it('→ exists', function () {
|
|
|
|
|
expect(Router).toExist()
|
|
|
|
|
expect(Router).not.toBeUndefined()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('→ add root node', function (done) {
|
|
|
|
@ -31,7 +31,7 @@ describe('Router', function () {
|
|
|
|
|
var router = new Router()
|
|
|
|
|
router.add(['/user', /^(\d+)$/], function (number) { return number })
|
|
|
|
|
router.route('/user/', function (err) {
|
|
|
|
|
expect(err).toBeA(NotFoundError)
|
|
|
|
|
expect(err).toBeInstanceOf(NotFoundError)
|
|
|
|
|
done()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
@ -39,9 +39,9 @@ describe('Router', function () {
|
|
|
|
|
it('→ get error in callback for missing handler', function (done) {
|
|
|
|
|
var router = new Router()
|
|
|
|
|
router.route('/some/fake/path', function (err, handlerResult) {
|
|
|
|
|
expect(err).toBeA(Error)
|
|
|
|
|
expect(err).toBeInstanceOf(Error)
|
|
|
|
|
expect(err.message).toMatch(/not found/)
|
|
|
|
|
expect(handlerResult).toNotExist()
|
|
|
|
|
expect(handlerResult).toBeUndefined()
|
|
|
|
|
done()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
@ -62,7 +62,7 @@ describe('Router', function () {
|
|
|
|
|
var router = new Router()
|
|
|
|
|
router.add(['/by/id', /\d+/], function () {})
|
|
|
|
|
router.route('/by/id/not-an-id', function (err) {
|
|
|
|
|
expect(err).toBeA(NotFoundError)
|
|
|
|
|
expect(err).toBeInstanceOf(NotFoundError)
|
|
|
|
|
done()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
@ -85,8 +85,8 @@ describe('Router', function () {
|
|
|
|
|
var router = new Router()
|
|
|
|
|
router.add(['by', 'order', /(\d+)/], function (one, two, three) {
|
|
|
|
|
expect(one).toBe('1')
|
|
|
|
|
expect(two).toNotExist()
|
|
|
|
|
expect(three).toNotExist()
|
|
|
|
|
expect(two).toBeUndefined()
|
|
|
|
|
expect(three).toBeUndefined()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.route('/by/order/1-2-3', function (err) {
|
|
|
|
@ -131,7 +131,7 @@ describe('Router', function () {
|
|
|
|
|
var router = new Router()
|
|
|
|
|
router.add(['/by/order', toInt], function () {})
|
|
|
|
|
router.route('/by/order/not-found', function (err) {
|
|
|
|
|
expect(err).toBeA(NotFoundError)
|
|
|
|
|
expect(err).toBeInstanceOf(NotFoundError)
|
|
|
|
|
done()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|