forked from pillarjs/hbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
48 lines (39 loc) · 1.34 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
var assert = require('assert');
var hbs = require("./lib/hbs");
var handlebars = hbs.handlebars;
assert.ok(handlebars != null);
var options = {
message: "foobar"
};
//testing out of the box configuration
var source = "testing {{message}}";
var template = hbs.compile(source, options);
var rendered = hbs.render(template, options);
assert.equal('testing foobar', rendered);
//fake handlebars conforming interface
var fakeHandlebars = {
compile: function(source, options) {
return function(template, options) {
return source;
}
},
render: function(tpl, options) {
return tpl();
}
};
module.exports = fakeHandlebars;
//setting handlebars to fake version
hbs.handlebars = fakeHandlebars;
var template = hbs.compile(source, options);
var rendered = hbs.render(template, options);
assert.equal('testing {{message}}', rendered);
//changing require path to go back to path of real handlebars
hbs.handlebarsPath = __dirname + '/support/handlebars/lib/handlebars';
var template = hbs.compile(source, options);
var rendered = hbs.render(template, options);
assert.equal('testing foobar', rendered);
//changing require path to use this file (which exports fake version)
hbs.handlebarsPath = __filename;
var template = hbs.compile(source, options);
var rendered = hbs.render(template, options);
assert.equal('testing {{message}}', rendered);