Fix some usages of .extend(…) in tests

rename newblaze.js to template.js
This commit is contained in:
David Greenspan
2014-05-28 15:50:06 -07:00
parent e728fb344b
commit acb772c6cb
4 changed files with 46 additions and 22 deletions

View File

@@ -1,6 +1,16 @@
var renderToDiv = function (comp) {
var renderToDiv = function (comp, optData) {
var div = document.createElement("DIV");
Blaze.renderComponent(comp, div);
if (optData == null) {
Blaze.renderComponent(comp, div);
} else {
var constructor =
(typeof comp === 'function' ? comp : comp.constructor);
Blaze.render(function () {
return Blaze.With(optData, function () {
return new constructor;
});
}).attach(div);
}
return div;
};
@@ -223,7 +233,7 @@ Tinytest.add("spacebars-tests - template_tests - inclusion dotted args", functio
return { baz: this.symbol + R.get() };
};
var div = renderToDiv(tmpl.extend({data: {symbol:'%'}}));
var div = renderToDiv(tmpl, {symbol:'%'});
test.equal(initCount, 1);
test.equal(canonicalizeHtml(div.innerHTML), '[%david]');
@@ -249,7 +259,7 @@ Tinytest.add("spacebars-tests - template_tests - inclusion slashed args", functi
return { baz: this.symbol + R.get() };
};
var div = renderToDiv(tmpl.extend({data: {symbol:'%'}}));
var div = renderToDiv(tmpl, {symbol:'%'});
test.equal(initCount, 1);
test.equal(canonicalizeHtml(div.innerHTML), '[%david]');
});

View File

@@ -1,7 +1,17 @@
// render and put in the document
var renderToDiv = function (comp) {
var renderToDiv = function (comp, optData) {
var div = document.createElement("DIV");
Blaze.renderComponent(comp, div);
if (optData == null) {
Blaze.renderComponent(comp, div);
} else {
var constructor =
(typeof comp === 'function' ? comp : comp.constructor);
Blaze.render(function () {
return Blaze.With(optData, function () {
return new constructor;
});
}).attach(div);
}
return div;
};
@@ -62,7 +72,7 @@ Tinytest.add("templating - table assembly", function(test) {
c.insert({bar:'a'});
c.insert({bar:'b'});
c.insert({bar:'c'});
var onscreen = renderToDiv(Template.test_table_each.extend({data: {foo: c.find()}}));
var onscreen = renderToDiv(Template.test_table_each, {foo: c.find()});
table = childWithTag(onscreen, "TABLE");
test.equal(table.rows.length, 3, table.parentNode.innerHTML);
@@ -90,8 +100,8 @@ Tinytest.add("templating - event handler this", function(test) {
});
var event_buf = [];
var containerDiv = renderToDiv(Template.test_event_data_with.extend({data:
Template.test_event_data_with.ONE}));
var containerDiv = renderToDiv(Template.test_event_data_with,
Template.test_event_data_with.ONE);
var cleanupDiv = addToBody(containerDiv);
var divs = containerDiv.getElementsByTagName("div");
@@ -180,7 +190,7 @@ Tinytest.add("templating - safestring", function(test) {
var obj = {fooprop: "<br>",
barprop: new Spacebars.SafeString("<hr>")};
var html = canonicalizeHtml(
renderToDiv(Template.test_safestring_a.extend({data: obj})).innerHTML);
renderToDiv(Template.test_safestring_a, obj).innerHTML);
test.equal(html,
"&lt;br&gt;<br><hr><hr>"+
@@ -258,7 +268,7 @@ Tinytest.add("templating - helpers and dots", function(test) {
var html;
html = canonicalizeHtml(
renderToDiv(Template.test_helpers_a.extend({data: dataObj})).innerHTML);
renderToDiv(Template.test_helpers_a, dataObj).innerHTML);
test.equal(html.match(/\S+/g), [
'platypus=bill', // helpers on Template object take first priority
'watermelon=seeds', // global helpers take second priority
@@ -268,7 +278,7 @@ Tinytest.add("templating - helpers and dots", function(test) {
]);
html = canonicalizeHtml(
renderToDiv(Template.test_helpers_b.extend({data: dataObj})).innerHTML);
renderToDiv(Template.test_helpers_b, dataObj).innerHTML);
test.equal(html.match(/\S+/g), [
// unknown properties silently fail
'unknown=',
@@ -277,7 +287,7 @@ Tinytest.add("templating - helpers and dots", function(test) {
]);
html = canonicalizeHtml(
renderToDiv(Template.test_helpers_c.extend({data: dataObj})).innerHTML);
renderToDiv(Template.test_helpers_c, dataObj).innerHTML);
test.equal(html.match(/\S+/g), [
// property gets are supposed to silently fail
'platypus.X=',
@@ -291,7 +301,7 @@ Tinytest.add("templating - helpers and dots", function(test) {
]);
html = canonicalizeHtml(
renderToDiv(Template.test_helpers_d.extend({data: dataObj})).innerHTML);
renderToDiv(Template.test_helpers_d, dataObj).innerHTML);
test.equal(html.match(/\S+/g), [
// helpers should get current data context in `this`
'daisygetter=petal',
@@ -305,7 +315,7 @@ Tinytest.add("templating - helpers and dots", function(test) {
]);
html = canonicalizeHtml(
renderToDiv(Template.test_helpers_e.extend({data: dataObj})).innerHTML);
renderToDiv(Template.test_helpers_e, dataObj).innerHTML);
test.equal(html.match(/\S+/g), [
'fancy.foo=bar',
'fancy.apple.banana=smoothie',
@@ -316,7 +326,7 @@ Tinytest.add("templating - helpers and dots", function(test) {
]);
html = canonicalizeHtml(
renderToDiv(Template.test_helpers_f.extend({data: dataObj})).innerHTML);
renderToDiv(Template.test_helpers_f, dataObj).innerHTML);
test.equal(html.match(/\S+/g), [
'fancyhelper.foo=bar',
'fancyhelper.apple.banana=smoothie',
@@ -329,7 +339,7 @@ Tinytest.add("templating - helpers and dots", function(test) {
// test significance of 'this', which prevents helper from
// shadowing property
html = canonicalizeHtml(
renderToDiv(Template.test_helpers_g.extend({data: dataObj})).innerHTML);
renderToDiv(Template.test_helpers_g, dataObj).innerHTML);
test.equal(html.match(/\S+/g), [
'platypus=eggs',
'this.platypus=weird'
@@ -340,7 +350,7 @@ Tinytest.add("templating - helpers and dots", function(test) {
Template.test_helpers_h.helperListFour = listFour;
html = canonicalizeHtml(
renderToDiv(Template.test_helpers_h.extend({data: dataObj})).innerHTML);
renderToDiv(Template.test_helpers_h, dataObj).innerHTML);
var trials =
html.match(/\(.*?\)/g);
test.equal(trials[0],
@@ -365,7 +375,7 @@ Tinytest.add("templating - rendered template", function(test) {
return this.x + 1;
};
var div = renderToDiv(Template.test_render_a.extend({data: {x: 123}}));
var div = renderToDiv(Template.test_render_a, {x: 123});
test.equal($(div).text().match(/\S+/)[0], "124");
var br1 = div.getElementsByTagName('br')[0];
@@ -393,7 +403,7 @@ Tinytest.add("templating - rendered template", function(test) {
return (+this) + 1;
};
div = renderToDiv(Template.test_render_b.extend({data: {x: 123}}));
div = renderToDiv(Template.test_render_b, {x: 123});
test.equal($(div).text().match(/\S+/)[0], "201");
var br1 = div.getElementsByTagName('br')[0];
@@ -451,7 +461,7 @@ Tinytest.add("templating - template arg", function (test) {
test.throws(function () { return self.findAll("*"); });
};
var div = renderToDiv(Template.test_template_arg_a.extend({data: {food: "pie"}}));
var div = renderToDiv(Template.test_template_arg_a, {food: "pie"});
var cleanupDiv = addToBody(div);
Deps.flush(); // cause `rendered` to be called
test.equal($(div).text(), "Greetings 1-bold Line");

View File

@@ -36,7 +36,7 @@ Package.on_use(function (api) {
api.add_files(['handlebars_backcompat.js']);
api.add_files(['newblaze.js']);
api.add_files(['template.js']);
});
Package.on_test(function (api) {

View File

@@ -90,5 +90,9 @@ UI.TemplateComponent = Blaze.Component.extend({
},
helpers: function (dict) {
_.extend(this, dict);
},
extend: function () {
throw new Error(
"Component#extend was part of a private API that has been removed");
}
});