Start view_tests for Blaze

Want to test view.onRendered and view.onMaterialized while nailing
down their API.
This commit is contained in:
David Greenspan
2014-08-13 15:02:11 -07:00
parent f35ce02196
commit b5507c33a7
2 changed files with 34 additions and 2 deletions

View File

@@ -39,7 +39,8 @@ Package.on_test(function (api) {
api.use('tinytest');
api.use('jquery'); // strong dependency, for testing jQuery backend
api.use('blaze');
api.use(['test-helpers', 'underscore'], 'client');
api.use('test-helpers');
api.use('underscore');
// ...
api.add_files('view_tests.js');
});

View File

@@ -0,0 +1,31 @@
if (Meteor.isClient) {
Tinytest.add("blaze - view - callbacks", function (test) {
var R = Blaze._ReactiveVar('foo');
var buf = '';
var v = Blaze.View(function () {
return R.get();
});
v.onViewCreated(function () {
buf += 'c';
});
v.onViewDestroyed(function () {
buf += 'd';
});
test.equal(buf, '');
var div = document.createElement("DIV");
Blaze.insert(Blaze.render(v), div);
test.equal(buf, 'c');
test.equal(canonicalizeHtml(div.innerHTML), "foo");
Blaze.remove(v);
test.equal(buf, 'cd');
test.equal(canonicalizeHtml(div.innerHTML), "");
});
}