Test that #each stops its cursors when removed

This commit is contained in:
Avital Oliver
2013-12-13 17:47:50 -08:00
parent 43beb6ff3b
commit b482c449d3
3 changed files with 26 additions and 0 deletions

View File

@@ -125,6 +125,8 @@ ObserveSequence = {
return {
stop: function () {
computation.stop();
if (activeObserveHandle)
activeObserveHandle.stop();
}
};
},

View File

@@ -263,3 +263,9 @@
{{foo}} {{bar}}
{{/with}}
</template>
<template name="spacebars_template_test_each_stops">
{{#each items}}
x
{{/each}}
</template>

View File

@@ -821,3 +821,21 @@ Tinytest.add('spacebars - templates - with someData', function (test) {
test.equal(someDataRuns, 1);
test.equal(trim(stripComments(div.innerHTML)), 'CCC YO');
});
Tinytest.add('spacebars - template - #each stops when rendered element is removed', function (test) {
var tmpl = Template.spacebars_template_test_each_stops;
var coll = new Meteor.Collection(null);
coll.insert({});
tmpl.items = function () { return coll.find(); };
var div = renderToDiv(tmpl);
divRendersTo(test, div, 'x');
// trigger #each component destroyed
$(div).remove();
// insert another document. cursor should no longer be observed so
// should have no effect.
coll.insert({});
divRendersTo(test, div, 'x');
});