Provide clear throw on {{#each}}

Fixes #773
This commit is contained in:
kpdecker
2014-05-27 10:54:22 -04:00
parent 3cdf14d294
commit 7172d167dd
2 changed files with 6 additions and 7 deletions
+1 -3
View File
@@ -97,10 +97,8 @@ function registerDefaultHelpers(instance) {
});
instance.registerHelper('each', function(context, options) {
// Allow for {{#each}}
if (!options) {
options = context;
context = this;
throw new Exception('Must pass iterator to #each');
}
var fn = options.fn, inverse = options.inverse;
+5 -4
View File
@@ -1,4 +1,4 @@
/*global CompilerContext, shouldCompileTo, compileWithPartials, handlebarsEnv */
/*global CompilerContext, shouldCompileTo, shouldThrow, compileWithPartials, handlebarsEnv */
describe('builtin helpers', function() {
describe('#if', function() {
it("if", function() {
@@ -182,9 +182,10 @@ describe('builtin helpers', function() {
});
it("each on implicit context", function() {
var string = "{{#each}}{{text}}! {{/each}}cruel world!";
var hash = [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}];
shouldCompileTo(string, [hash], "goodbye! Goodbye! GOODBYE! cruel world!");
shouldThrow(function() {
var template = CompilerContext.compile("{{#each}}{{text}}! {{/each}}cruel world!");
template({});
}, handlebarsEnv.Exception, 'Must pass iterator to #each');
});
});