1 | var wayfarer = require('../')
|
2 | var getAllRoutes = require('../get-all-routes')
|
3 | var tape = require('tape')
|
4 |
|
5 | tape('getAllRoutes', function (t) {
|
6 | t.test('should assert input types', function (t) {
|
7 | t.plan(1)
|
8 | t.throws(getAllRoutes.bind(null), /function/, 'assert first arg is function')
|
9 | })
|
10 |
|
11 | t.test('should getAllRoutes', function (t) {
|
12 | t.plan(4)
|
13 | var router = wayfarer()
|
14 | router.on('/foo', function (x, y) { return x * y })
|
15 | router.on('/bar', function (x, y) { return x / y })
|
16 |
|
17 | var routes = getAllRoutes(router)
|
18 |
|
19 | t.equal(routes instanceof Object, true)
|
20 | t.equal(Object.keys(routes).length, 2)
|
21 | t.equal(typeof routes['/foo'], 'function')
|
22 | t.equal(typeof routes['/bar'], 'function')
|
23 | })
|
24 |
|
25 | t.test('should getAllRoutes from a nested tree', function (t) {
|
26 | t.plan(6)
|
27 | var router = wayfarer()
|
28 | router.on('/foo', function (x, y) { return x * y + 2 })
|
29 | router.on('/foo/baz', function (x, y) { return x * y })
|
30 | router.on('/bar/bin/barb', function (x, y) { return x / y })
|
31 | router.on('/bar/bin/bla', function (x, y) { return x / y })
|
32 |
|
33 | var routes = getAllRoutes(router)
|
34 |
|
35 | t.equal(routes instanceof Object, true)
|
36 | t.equal(Object.keys(routes).length, 4)
|
37 | t.equal(typeof routes['/foo'], 'function')
|
38 | t.equal(typeof routes['/foo/baz'], 'function')
|
39 | t.equal(typeof routes['/bar/bin/barb'], 'function')
|
40 | t.equal(typeof routes['/bar/bin/bla'], 'function')
|
41 | })
|
42 |
|
43 | t.test('should getAllRoutes from a routes with params', function (t) {
|
44 | t.plan(5)
|
45 | var router = wayfarer()
|
46 | router.on('/foo', function (x, y) { return x / y })
|
47 | router.on('/foo/:slug', function (x, y) { return x * y + 2 })
|
48 | router.on('/foo/:slug/:id', function (x, y) { return x * y })
|
49 |
|
50 | var routes = getAllRoutes(router)
|
51 |
|
52 | t.equal(routes instanceof Object, true)
|
53 | t.equal(Object.keys(routes).length, 3)
|
54 | t.equal(typeof routes['/foo'], 'function')
|
55 | t.equal(typeof routes['/foo/:slug'], 'function')
|
56 | t.equal(typeof routes['/foo/:slug/:id'], 'function')
|
57 | })
|
58 | })
|