-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.js
90 lines (63 loc) · 2.01 KB
/
test.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
/**
* Test dependencies.
*/
var should = require('should')
, jade = require('jade')
, jadevu = require('./lib/jadevu')
, vm = require('vm')
, fs = require('fs')
/**
* Render utility.
*/
function render (fixture, opts) {
return jade.compile(
fs.readFileSync(__dirname + '/test/' + fixture + '.jade')
, opts
)();
};
/**
* Executes client side code.
*/
function execute (str) {
var str = str.replace(/<script>/g, '').replace(/<\/script>/g, '')
, script = vm.createScript(str)
, obj = { window: {} }
script.runInNewContext(obj);
return obj.window.template;
};
/**
* Tests.
*/
console.log('Testing that template wont render without and id');
var thrown = false;
try {
render('noid');
} catch (e) {
e.message.should.include.string('`id`');
thrown = true;
}
thrown.should.be.true;
console.log('Testing that compiling a template includes the wrapper');
render('wrapper').should.include.string('template');
render('wrapper').should.include.string('template._');;
render('wrapper').should.include.string('noConflict');
render('wrapper').should.include.string('<script>');
console.log('Testing that the wrapper appears only once');
render('twice').should.include.string('<span>Hello world</span>');
render('twice').should.include.string('uno');
render('twice').should.include.string('dos');
render('twice').indexOf('.noConflict').should.equal(
render('twice').lastIndexOf('.noConflict')
);
console.log('Testing that templates compile');
var template = execute(render('compile'));
template('woot', { times: 5 }).should.equal(
'<div><a>woot</a><a>woot</a><a>woot</a><a>woot</a><a>woot</a></div>'
);
template('tj', { woot: 'haha' }).should.equal('<p>haha</p>');
console.log('Testing that templates with multiple lines compile');
var template = execute(render('multiple'));
template('woot').should.equal('<div>woot\n<p>woot\n</p></div>');
console.log('Testing that templates dont include debug code');
render('twice').should.not.include.string('.lineno');
console.log('+ All tests passed');