forked from assemble/assemble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.middleware.js
62 lines (54 loc) · 1.32 KB
/
app.middleware.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
'use strict';
require('mocha');
require('should');
var assert = require('assert');
var support = require('./support');
var App = support.resolve();
var app;
describe('app.middleware', function() {
beforeEach(function() {
app = new App();
app.engine('tmpl', require('engine-base'));
app.create('pages');
});
it('should call the all method for every middleware method:', function() {
var i = 0;
app.all(/./, function(view, next) {
assert(typeof view.path === 'string');
i++;
next();
});
assert(i === 0);
app.page('foo.tmpl', {content: 'foo'});
assert(i === 1);
});
it('should call the onLoad method when a view is loaded:', function() {
var i = 0;
app.onLoad(/./, function(view, next) {
assert(typeof view.path === 'string');
i++;
next();
});
assert(i === 0);
app.page('foo.tmpl', {content: 'foo'});
assert(i === 1);
});
it('should emit an event when a handler is called:', function(cb) {
var i = 0;
app.on('onLoad', function() {
i++;
});
app.on('preRender', function() {
i++;
});
app.on('preCompile', function() {
i++;
});
app.page('foo.tmpl', {content: 'foo'})
.render(function(err) {
if (err) return cb(err);
assert(i === 3);
cb();
});
});
});