-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathdefines.test.js
29 lines (24 loc) · 958 Bytes
/
defines.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
'use strict';
var doT = require('..');
var assert = require('assert');
describe('defines', function() {
describe('without parameters', function() {
it('should render define', function(){
testDef('{{##def.tmp:<div>{{!it.foo}}</div>#}}{{#def.tmp}}');
});
it('should render define if it is passed to doT.compile', function() {
testDef('{{#def.tmp}}', {tmp: '<div>{{!it.foo}}</div>'});
});
});
describe('with parameters', function() {
it('should render define', function(){
testDef('{{##def.tmp:foo:<div>{{!foo}}</div>#}}{{ var bar = it.foo; }}{{# def.tmp:bar }}');
});
});
function testDef(tmpl, defines) {
var fn = doT.compile(tmpl, defines);
assert.equal(fn({foo:'http'}), '<div>http</div>');
assert.equal(fn({foo:'http://abc.com'}), '<div>http://abc.com</div>');
assert.equal(fn({}), '<div></div>');
}
});