diff options
author | kpdecker <kpdecker@gmail.com> | 2013-01-14 01:01:02 -0600 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2013-01-14 01:01:02 -0600 |
commit | 5e5f0dce9c352f490f1f1e58fd7d0f76dd006cac (patch) | |
tree | 88932d94a0b99ab3dea7855ecc45c04ac0e4e0d9 /spec/qunit_spec.js | |
parent | f5079765ff2ffaa33f82281b8eddd908781ae7d7 (diff) | |
download | handlebars.js-5e5f0dce9c352f490f1f1e58fd7d0f76dd006cac.zip handlebars.js-5e5f0dce9c352f490f1f1e58fd7d0f76dd006cac.tar.gz handlebars.js-5e5f0dce9c352f490f1f1e58fd7d0f76dd006cac.tar.bz2 |
Expand helperMissing test coverage
Fixes #216
Diffstat (limited to 'spec/qunit_spec.js')
-rw-r--r-- | spec/qunit_spec.js | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js index 526c397..5e20ac2 100644 --- a/spec/qunit_spec.js +++ b/spec/qunit_spec.js @@ -24,12 +24,6 @@ if (!Handlebars) { suite("basic context"); -Handlebars.registerHelper('helperMissing', function(helper, context) { - if(helper === "link_to") { - return new Handlebars.SafeString("<a>" + context + "</a>"); - } -}); - function shouldCompileTo(string, hashOrArray, expected, message) { shouldCompileToWithPartials(string, hashOrArray, false, expected, message); } @@ -46,7 +40,7 @@ function compileWithPartials(string, hashOrArray, partials) { if(helpers) { for(var prop in Handlebars.helpers) { - helpers[prop] = Handlebars.helpers[prop]; + helpers[prop] = helpers[prop] || Handlebars.helpers[prop]; } } @@ -605,10 +599,25 @@ test("constructing a safestring from a string and checking its type", function() suite("helperMissing"); test("if a context is not found, helperMissing is used", function() { + shouldThrow(function() { + var template = CompilerContext.compile("{{hello}} {{link_to world}}"); + template({}); + }, [Error, "Could not find property 'link_to'"], "Should throw exception"); +}); + +test("if a context is not found, custom helperMissing is used", function() { var string = "{{hello}} {{link_to world}}"; var context = { hello: "Hello", world: "world" }; - shouldCompileTo(string, context, "Hello <a>world</a>"); + var helpers = { + helperMissing: function(helper, context) { + if(helper === "link_to") { + return new Handlebars.SafeString("<a>" + context + "</a>"); + } + } + }; + + shouldCompileTo(string, [context, helpers], "Hello <a>world</a>"); }); suite("knownHelpers"); |