forked from assemble/assemble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.route.js
94 lines (75 loc) · 2.21 KB
/
app.route.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
'use strict';
require('mocha');
require('should');
var assert = require('assert');
var App = require('..');
var app;
describe('app.route', function() {
beforeEach(function() {
app = new App();
});
describe('routes', function() {
it('should create a route for the given path:', function(cb) {
app = new App();
app.create('posts');
app.on('all', function(msg) {
assert(msg === 'cb');
cb();
});
app.route('blog/:title')
.all(function(view, next) {
app.emit('all', 'cb');
next();
});
app.post('whatever', {path: 'blog/foo.js', content: 'bar baz'});
});
it('should emit events when a route method is called:', function(cb) {
app = new App();
app.create('posts');
app.on('onLoad', function(view) {
assert(view.path === 'blog/foo.js');
cb();
});
app.param('title', function(view, next, title) {
assert(title === 'foo.js');
next();
});
app.onLoad('blog/:title', function(view, next) {
assert(view.path === 'blog/foo.js');
next();
});
app.post('whatever', {path: 'blog/foo.js', content: 'bar baz'});
});
it('should emit errors', function(cb) {
app = new App();
app.create('posts');
app.on('error', function(err) {
assert(err.message === 'false == true');
cb();
});
// wrong...
app.param('title', function(view, next, title) {
assert(title === 'fo.js');
next();
});
app.onLoad('/blog/:title', function(view, next) {
assert(view.path === '/blog/foo.js');
next();
});
app.post('whatever', {path: '/blog/foo.js', content: 'bar baz'});
});
it('should have path property', function() {
var route = new app.Route('/blog/:year/:month/:day/:slug').all([
function() {}
]);
route.path.should.equal('/blog/:year/:month/:day/:slug');
});
it('should have stack property', function() {
var route = new app.Route('/blog/:year/:month/:day/:slug').all([
function() {}
]);
route.stack.should.be.instanceof(Array);
route.stack.should.have.length(1);
});
});
});