Move more testing mutations into the environment
This commit is contained in:
+2
-1
@@ -1,4 +1,4 @@
|
||||
import { HandlebarsEnvironment } from "./handlebars/base";
|
||||
import { HandlebarsEnvironment, createFrame } from "./handlebars/base";
|
||||
|
||||
// Each of these augment the Handlebars object. No need to setup here.
|
||||
// (This is done to easily share code between commonjs and browse envs)
|
||||
@@ -23,6 +23,7 @@ var create = function() {
|
||||
hb.compile = compile;
|
||||
hb.precompile = precompile;
|
||||
hb.template = template;
|
||||
hb.createFrame = createFrame;
|
||||
|
||||
return hb;
|
||||
};
|
||||
|
||||
+6
-3
@@ -47,6 +47,12 @@ describe('builtin helpers', function() {
|
||||
});
|
||||
|
||||
describe('#each', function() {
|
||||
beforeEach(function() {
|
||||
handlebarsEnv.registerHelper('detectDataInsideEach', function(options) {
|
||||
return options.data && options.data.exclaim;
|
||||
});
|
||||
});
|
||||
|
||||
it("each", function() {
|
||||
var string = "{{#each goodbyes}}{{text}}! {{/each}}cruel {{world}}!";
|
||||
var hash = {goodbyes: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"};
|
||||
@@ -104,9 +110,6 @@ describe('builtin helpers', function() {
|
||||
equal(result, 'a!b!c!', 'should output data');
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('detectDataInsideEach', function(options) {
|
||||
return options.data && options.data.exclaim;
|
||||
});
|
||||
});
|
||||
|
||||
it("#log", function() {
|
||||
|
||||
+1
-3
@@ -19,12 +19,10 @@ describe('data', function() {
|
||||
equals("hello", result, "@foo retrieves template data");
|
||||
});
|
||||
|
||||
var objectCreate = Handlebars.createFrame;
|
||||
|
||||
it("deep @foo triggers automatic top-level data", function() {
|
||||
var template = CompilerContext.compile('{{#let world="world"}}{{#if foo}}{{#if foo}}Hello {{@world}}{{/if}}{{/if}}{{/let}}');
|
||||
|
||||
var helpers = objectCreate(Handlebars.helpers);
|
||||
var helpers = Handlebars.createFrame(handlebarsEnv.helpers);
|
||||
|
||||
helpers.let = function(options) {
|
||||
var frame = Handlebars.createFrame(options.data);
|
||||
|
||||
+13
-18
@@ -161,7 +161,7 @@ describe('helpers', function() {
|
||||
});
|
||||
|
||||
it("the helper hash should augment the global hash", function() {
|
||||
Handlebars.registerHelper('test_helper', function() { return 'found it!'; });
|
||||
handlebarsEnv.registerHelper('test_helper', function() { return 'found it!'; });
|
||||
|
||||
shouldCompileTo(
|
||||
"{{test_helper}} {{#if cruel}}Goodbye {{cruel}} {{world}}!{{/if}}", [
|
||||
@@ -173,26 +173,21 @@ describe('helpers', function() {
|
||||
});
|
||||
|
||||
it("Multiple global helper registration", function() {
|
||||
var helpers = Handlebars.helpers;
|
||||
try {
|
||||
Handlebars.helpers = {};
|
||||
var helpers = handlebarsEnv.helpers;
|
||||
handlebarsEnv.helpers = {};
|
||||
|
||||
Handlebars.registerHelper({
|
||||
'if': helpers['if'],
|
||||
world: function() { return "world!"; },
|
||||
test_helper: function() { return 'found it!'; }
|
||||
});
|
||||
handlebarsEnv.registerHelper({
|
||||
'if': helpers['if'],
|
||||
world: function() { return "world!"; },
|
||||
test_helper: function() { return 'found it!'; }
|
||||
});
|
||||
|
||||
shouldCompileTo(
|
||||
"{{test_helper}} {{#if cruel}}Goodbye {{cruel}} {{world}}!{{/if}}",
|
||||
[{cruel: "cruel"}],
|
||||
"found it! Goodbye cruel world!!");
|
||||
} finally {
|
||||
if (helpers) {
|
||||
Handlebars.helpers = helpers;
|
||||
}
|
||||
}
|
||||
shouldCompileTo(
|
||||
"{{test_helper}} {{#if cruel}}Goodbye {{cruel}} {{world}}!{{/if}}",
|
||||
[{cruel: "cruel"}],
|
||||
"found it! Goodbye cruel world!!");
|
||||
});
|
||||
|
||||
it("negative number literals work", function() {
|
||||
var string = 'Message: {{hello -12}}';
|
||||
var hash = {};
|
||||
|
||||
+2
-2
@@ -70,7 +70,7 @@ describe('partials', function() {
|
||||
});
|
||||
|
||||
it("Global Partials", function() {
|
||||
Handlebars.registerPartial('global_test', '{{another_dude}}');
|
||||
handlebarsEnv.registerPartial('global_test', '{{another_dude}}');
|
||||
|
||||
var string = "Dudes: {{> shared/dude}} {{> global_test}}";
|
||||
var dude = "{{name}}";
|
||||
@@ -79,7 +79,7 @@ describe('partials', function() {
|
||||
});
|
||||
|
||||
it("Multiple partial registration", function() {
|
||||
Handlebars.registerPartial({
|
||||
handlebarsEnv.registerPartial({
|
||||
'shared/dude': '{{name}}',
|
||||
global_test: '{{another_dude}}'
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user