dot
Version:
Concise and fast javascript templating compatible with nodejs and other javascript environments
29 lines (24 loc) • 958 B
JavaScript
;
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>');
}
});