Files
handlebars.js/spec/runtime.js
T
kpdecker 2b3fdf7ea8 Additional test coverage cleanup
Also fixes the template._child implementation which broke with the depthed work.
2014-08-23 18:52:30 -05:00

57 lines
1.9 KiB
JavaScript

/*globals Handlebars, shouldThrow */
describe('runtime', function() {
describe('#template', function() {
it('should throw on invalid templates', function() {
shouldThrow(function() {
Handlebars.template({});
}, Error, 'Unknown template object: object');
shouldThrow(function() {
Handlebars.template();
}, Error, 'Unknown template object: undefined');
shouldThrow(function() {
Handlebars.template('');
}, Error, 'Unknown template object: string');
});
it('should throw on version mismatch', function() {
shouldThrow(function() {
Handlebars.template({
main: true,
compiler: [Handlebars.COMPILER_REVISION + 1]
});
}, Error, /Template was precompiled with a newer version of Handlebars than the current runtime/);
shouldThrow(function() {
Handlebars.template({
main: true,
compiler: [Handlebars.COMPILER_REVISION - 1]
});
}, Error, /Template was precompiled with an older version of Handlebars than the current runtime/);
shouldThrow(function() {
Handlebars.template({
main: true
});
}, Error, /Template was precompiled with an older version of Handlebars than the current runtime/);
});
});
describe('#child', function() {
if (!Handlebars.compile) {
return;
}
it('should throw for depthed methods', function() {
shouldThrow(function() {
var template = Handlebars.compile('{{#foo}}{{../bar}}{{/foo}}');
template._setup({});
template._setup({});
template._child(1);
}, Error, '_child can not be used with depthed templates');
});
it('should expose child template', function() {
var template = Handlebars.compile('{{#foo}}bar{{/foo}}');
equal(template._child(1)(), 'bar');
equal(template._child(1)(), 'bar');
});
});
});