Add test cases

master
Buddy Sandidge 9 years ago
parent 2784f9d492
commit 47c65ad9c7

@ -58,6 +58,15 @@ describe('Router', function () {
}) })
}) })
it('→ regex routes can return NotFoundError', function (done) {
var router = new Router()
router.add(['/by/id', /\d+/], function () {})
router.route('/by/id/not-an-id', function (err) {
expect(err).toBeA(NotFoundError)
done()
})
})
it('→ get based on regex with multiple captures global', function (done) { it('→ get based on regex with multiple captures global', function (done) {
var router = new Router() var router = new Router()
router.add(['by', 'order', /(\d+)/g], function (one, two, three) { router.add(['by', 'order', /(\d+)/g], function (one, two, three) {
@ -98,7 +107,6 @@ describe('Router', function () {
router.route('/by/order/123', {args: [api]}) router.route('/by/order/123', {args: [api]})
}) })
it('→ get based on function', function (done) {
function toInt(part) { function toInt(part) {
var results = /^(\d+)$/.exec(part) var results = /^(\d+)$/.exec(part)
if (results) { if (results) {
@ -107,7 +115,7 @@ describe('Router', function () {
return null return null
} }
} }
it('→ get based on function', function (done) {
var router = new Router() var router = new Router()
router.add(['by', 'order', toInt], function (val) { router.add(['by', 'order', toInt], function (val) {
expect(val).toBe(123) expect(val).toBe(123)
@ -119,6 +127,15 @@ describe('Router', function () {
}) })
}) })
it('→ function routes can return NotFoundError', function (done) {
var router = new Router()
router.add(['/by/order', toInt], function () {})
router.route('/by/order/not-found', function (err) {
expect(err).toBeA(NotFoundError)
done()
})
})
it('→ check not found error', function (done) { it('→ check not found error', function (done) {
var router = new Router() var router = new Router()
router.route('/not/real/id', function (err) { router.route('/not/real/id', function (err) {

Loading…
Cancel
Save