forked from jazzychad/template.node.js
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
44 lines (35 loc) · 1.17 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
(function() {
var sys = require('sys'),
test = require('mjsunit'),
template = require('./template'),
pending_callbacks = 0;
function expect_callback() {
pending_callbacks += 1;
}
function receive_callback() {
pending_callbacks -= 1;
}
var myobj = {obj : {num: 5, person:'Jack'}};
var myobj2 = {obj : {num: 10, person:'Jill'}};
expect_callback();
template.create('./tmpls/t1.template', function(my_template_function) {
receive_callback();
test.assertEquals('5 apples for Jack ', my_template_function(myobj));
});
expect_callback();
template.create('./tmpls/t2.template', function(my_template_function) {
receive_callback();
test.assertEquals('Bob', my_template_function({name:'Bob'}));
});
expect_callback();
template.create('./tmpls/t3.template', function(my_template_function) {
var data = {users: [{name:'Chad', age:25}, {name:'Bob', age:40}]};
receive_callback();
test.assertEquals('Chad is 25 years old.\nBob is 40 years old.\n', my_template_function(data));
});
// assert that all callbacks were called within the alloted time and exit
setTimeout(function () {
test.assertEquals(0, pending_callbacks);
process.exit();
}, 50);
}());