Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50675 views
1
/*
2
* path-test.js: Tests for the core `.path()` method.
3
*
4
* (C) 2011, Nodejitsu Inc.
5
* MIT LICENSE
6
*
7
*/
8
9
var assert = require('assert'),
10
vows = require('vows'),
11
director = require('../../../lib/director');
12
13
vows.describe('director/core/path').addBatch({
14
"An instance of director.Router": {
15
topic: function () {
16
var that = this;
17
that.matched = {};
18
that.matched['foo'] = [];
19
that.matched['newyork'] = [];
20
21
var router = new director.Router({
22
'/foo': function () { that.matched['foo'].push('foo'); }
23
});
24
return router;
25
},
26
"the path() method": {
27
"should create the correct nested routing table": function (router) {
28
var that = this;
29
router.path('/regions', function () {
30
this.on('/:state', function(country) {
31
that.matched['newyork'].push('new york');
32
});
33
});
34
35
assert.isFunction(router.routes.foo.on);
36
assert.isObject(router.routes.regions);
37
assert.isFunction(router.routes.regions['([._a-zA-Z0-9-]+)'].on);
38
},
39
"should dispatch the function correctly": function (router) {
40
router.dispatch('on', '/regions/newyork')
41
router.dispatch('on', '/foo');
42
assert.equal(this.matched['foo'].length, 1);
43
assert.equal(this.matched['newyork'].length, 1);
44
assert.equal(this.matched['foo'][0], 'foo');
45
assert.equal(this.matched['newyork'][0], 'new york');
46
}
47
}
48
}
49
}).export(module);
50
51