You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB
JavaScript

var expect = require('expect')
var RouteNode = require('../lib/route-node')
module.exports = describe('RouteNode', function () {
it('→ exists', function () {
expect(new RouteNode()).toExist()
})
describe('→ add nodes', function () {
var node = null
var callback = function () {}
var context = {}
beforeEach(function () {
node = new RouteNode()
})
it('→ add root node', function (done) {
node.add([], callback, context)
node.get([], [], function (err, func, cbContext, args) {
expect(err).toBe(null)
expect(func).toBe(callback)
expect(cbContext).toBe(context)
expect(args).toEqual([])
done()
})
})
it('→ get nested callback', function (done) {
node.add(['nested'], callback, context)
node.get(['nested'], [], function (err, func, cbContext, args) {
expect(err).toBe(null)
expect(func).toBe(callback)
expect(cbContext).toBe(context)
expect(args).toEqual([])
done()
})
})
it('→ get error callback for not found', function (done) {
node.get(['fake', 'route'], [], function (err, func, cbContext, args) {
expect(err).toBeA(Error)
expect(err.message).toMatch(/not found/)
expect(func).toNotExist()
expect(cbContext).toNotExist()
expect(args).toNotExist()
done()
})
})
})
})