summaryrefslogtreecommitdiffstats
path: root/spec/qunit_spec.js
diff options
context:
space:
mode:
authorRaimonds Simanovskis <raimonds.simanovskis@gmail.com>2011-01-23 11:55:48 +0200
committerRaimonds Simanovskis <raimonds.simanovskis@gmail.com>2011-01-23 11:55:48 +0200
commitada5a95f9ce9af348e7f0fb223aa78b4762d97d8 (patch)
tree09d8053942b94efb83e9779400707e48eb52a1b6 /spec/qunit_spec.js
parent65b421ee4d3a10cbb365c82a4c2400b8aa4053f8 (diff)
downloadhandlebars.js-ada5a95f9ce9af348e7f0fb223aa78b4762d97d8.zip
handlebars.js-ada5a95f9ce9af348e7f0fb223aa78b4762d97d8.tar.gz
handlebars.js-ada5a95f9ce9af348e7f0fb223aa78b4762d97d8.tar.bz2
improved "with" and "each" helpers to support function as argument
Diffstat (limited to 'spec/qunit_spec.js')
-rw-r--r--spec/qunit_spec.js28
1 files changed, 27 insertions, 1 deletions
diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js
index 1453189..8bbade1 100644
--- a/spec/qunit_spec.js
+++ b/spec/qunit_spec.js
@@ -490,12 +490,19 @@ test("if a context is not found, helperMissing is used", function() {
module("built-in helpers");
-test("with", function() {
+test("with non-function argument", function() {
var string = "{{#with person}}{{first}} {{last}}{{/with}}";
shouldCompileTo(string, {person: {first: "Alan", last: "Johnson"}}, "Alan Johnson");
});
+test("with function argument", function() {
+ var string = "{{#with person}}{{first}} {{last}}{{/with}}";
+
+ shouldCompileTo(string, {person: function() {return {first: this.firsName, last: this.lastName};},
+ firsName: "Alan", lastName: "Johnson"}, "Alan Johnson");
+});
+
test("if with non-function argument", function() {
var string = "{{#if goodbye}}GOODBYE {{/if}}cruel {{world}}!";
shouldCompileTo(string, {goodbye: true, world: "world"}, "GOODBYE cruel world!",
@@ -519,3 +526,22 @@ test("if with function argument", function() {
shouldCompileTo(string, {goodbye: function() {return this.foo}, world: "world"}, "cruel world!",
"if with function does not show the contents when returns undefined");
});
+
+test("each with non-function argument", function() {
+ var string = "{{#each goodbyes}}{{text}}! {{/each}}cruel {{world}}!"
+ var hash = {goodbyes: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"};
+ shouldCompileTo(string, hash, "goodbye! Goodbye! GOODBYE! cruel world!",
+ "each with array argument iterates over the contents when not empty");
+ shouldCompileTo(string, {goodbyes: [], world: "world"}, "cruel world!",
+ "each with array argument ignores the contents when empty");
+});
+
+test("each with function argument", function() {
+ var string = "{{#each goodbyes}}{{text}}! {{/each}}cruel {{world}}!"
+ var hash = {goodbyes: function() {return this.texts;},
+ texts: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"};
+ shouldCompileTo(string, hash, "goodbye! Goodbye! GOODBYE! cruel world!",
+ "each with function argument returning array iterates over the contents when not empty");
+ shouldCompileTo(string, {goodbyes: [], world: "world"}, "cruel world!",
+ "each with function argument returning array ignores the contents when empty");
+});