diff options
author | kpdecker <kpdecker@gmail.com> | 2014-08-15 00:05:37 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2014-08-15 00:05:37 -0500 |
commit | 9f07a3495551f26020a49c90e33150b9fa6abf73 (patch) | |
tree | b0b76ebbc8da9b37e38215f6acf72012aac70a6c /spec/builtins.js | |
parent | 6f22ec1e01264f443820a8f89b8a7e2edcf89abf (diff) | |
download | handlebars.js-9f07a3495551f26020a49c90e33150b9fa6abf73.zip handlebars.js-9f07a3495551f26020a49c90e33150b9fa6abf73.tar.gz handlebars.js-9f07a3495551f26020a49c90e33150b9fa6abf73.tar.bz2 |
Additional test coverage
Diffstat (limited to 'spec/builtins.js')
-rw-r--r-- | spec/builtins.js | 102 |
1 files changed, 90 insertions, 12 deletions
diff --git a/spec/builtins.js b/spec/builtins.js index 77f3701..d2fa88f 100644 --- a/spec/builtins.js +++ b/spec/builtins.js @@ -66,9 +66,29 @@ describe('builtin helpers', function() { "each with array argument ignores the contents when empty"); }); + it('each without data', function() { + var string = '{{#each goodbyes}}{{text}}! {{/each}}cruel {{world}}!'; + var hash = {goodbyes: [{text: 'goodbye'}, {text: 'Goodbye'}, {text: 'GOODBYE'}], world: 'world'}; + shouldCompileTo(string, [hash,,,,false], 'goodbye! Goodbye! GOODBYE! cruel world!'); + + hash = {goodbyes: 'cruel', world: 'world'}; + shouldCompileTo('{{#each .}}{{.}}{{/each}}', [hash,,,,false], 'cruelworld'); + }); + + it('each without context', function() { + var string = '{{#each goodbyes}}{{text}}! {{/each}}cruel {{world}}!'; + shouldCompileTo(string, [,,,,], 'cruel !'); + }); + it("each with an object and @key", function() { var string = "{{#each goodbyes}}{{@key}}. {{text}}! {{/each}}cruel {{world}}!"; - var hash = {goodbyes: {"<b>#1</b>": {text: "goodbye"}, 2: {text: "GOODBYE"}}, world: "world"}; + + function Clazz() { + this['<b>#1</b>'] = {text: 'goodbye'}; + this[2] = {text: 'GOODBYE'}; + } + Clazz.prototype.foo = 'fail'; + var hash = {goodbyes: new Clazz(), world: 'world'}; // Object property iteration order is undefined according to ECMA spec, // so we need to check both possible orders @@ -193,19 +213,77 @@ describe('builtin helpers', function() { }); }); - it("#log", function() { - var string = "{{log blah}}"; - var hash = { blah: "whee" }; + describe("#log", function() { + var info, + error; + beforeEach(function() { + info = console.info; + error = console.error; + }); + afterEach(function() { + console.info = info; + console.error = error; + }); + + it('should call logger at default level', function() { + var string = "{{log blah}}"; + var hash = { blah: "whee" }; - var levelArg, logArg; - handlebarsEnv.log = function(level, arg){ - levelArg = level; - logArg = arg; - }; + var levelArg, logArg; + handlebarsEnv.log = function(level, arg){ + levelArg = level; + logArg = arg; + }; - shouldCompileTo(string, hash, "", "log should not display"); - equals(1, levelArg, "should call log with 1"); - equals("whee", logArg, "should call log with 'whee'"); + shouldCompileTo(string, hash, "", "log should not display"); + equals(1, levelArg, "should call log with 1"); + equals("whee", logArg, "should call log with 'whee'"); + }); + it('should call logger at data level', function() { + var string = "{{log blah}}"; + var hash = { blah: "whee" }; + + var levelArg, logArg; + handlebarsEnv.log = function(level, arg){ + levelArg = level; + logArg = arg; + }; + + shouldCompileTo(string, [hash,,,,{level: '03'}], ""); + equals(3, levelArg); + equals("whee", logArg); + }); + it('should not output to console', function() { + var string = "{{log blah}}"; + var hash = { blah: "whee" }; + + console.info = function() { + throw new Error(); + }; + + shouldCompileTo(string, hash, "", "log should not display"); + }); + it('should log at data level', function() { + var string = "{{log blah}}"; + var hash = { blah: "whee" }; + var called; + + console.error = function(log) { + equals("whee", log); + called = true; + }; + + shouldCompileTo(string, [hash,,,,{level: '03'}], ""); + equals(true, called); + }); + it('should handle missing logger', function() { + var string = "{{log blah}}"; + var hash = { blah: "whee" }; + + console.error = undefined; + + shouldCompileTo(string, [hash,,,,{level: '03'}], ""); + }); }); |