Open GabrielGM opened 9 years ago
+1
I ran into the same problem... It was telling me that Template.insert isn't a function and made some research to end up using UI.insert
// render the template var div = document.body; var comp = UI.render(Template.meteorErrors);
UI.insert(comp, div);
//Template.insert(Template.render(Template.meteorErrors), document.body);
which is pretty much the same as you proposed
So, I was really having to hunt and peck to find this - Exactly where to add this new support for "ui"
I decided to write a full manual patch for everyone else coming after me. Hopefully they will fix this in the book and we won't have this problem anymore. Until then - here's how to fix it.
Here are the two files I have:
[microscope dir]/packages/errors/package.js:
Package.describe({
name: "autoschematic:errors",
summary: "A pattern to display application errors to the user",
version: "1.0.0"
});
Package.onUse(function (api, where) {
api.versionsFrom('0.9.0');
api.use(['minimongo', 'mongo-livedata', 'templating'], 'client');
api.addFiles(['errors.js', 'errors_list.html', 'errors_list.js'], 'client');
if (api.export)
api.export('Errors');
});
Package.onTest(function(api) {
api.use('autoschematic:errors', 'client');
api.use(['tinytest', 'ui', 'test-helpers', 'templating'], 'client');
api.addFiles('errors_tests.js', 'client');
});
The trick is there in the Package.onTest
function you're putting:
api.use(['tinytest', 'ui', 'test-helpers', 'templating'], 'client');
And then your [microscope dir]/packages/errors/errors_tests.js:
file will look like this:
Tinytest.add("Errors - collection", function(test) {
test.equal(Errors.collection.find({}).count(), 0);
Errors.throw('A new error!');
test.equal(Errors.collection.find({}).count(), 1);
Errors.collection.remove({});
});
Tinytest.addAsync("Errors - template", function(test, done) {
Errors.throw('A new error!');
test.equal(Errors.collection.find({}).count(), 1);
// render the template
UI.insert(UI.render(Template.meteorErrors), document.body);
Meteor.setTimeout(function() {
test.equal(Errors.collection.find({}).count(), 0);
done();
}, 3500);
});
Notice that as people are saying the line
UI.insert(UI.render(Template.meteorErrors), document.body);
is different than in the book where it has this line as
Template.insert(Template.render(Template.meteorErrors), document.body);
I thought that an extended full explanation was in order for this problem.
Adding this I was able to render:
Thank you to everyone else who helped me get here: @MGDSoft @mbeauchamp7 @GabrielGM And this Issue #468 and the comments on this commit sidebar9-5-2
In the
packages/tmeasday:errors/errors_tests.js
file, the book sayswhen the repo says :
The UI version is the good one for the current version of Meteor (1.2)