Add a test for cleaning up event handlers when template is destroyed

This commit is contained in:
Emily Stark
2014-05-15 13:55:55 -07:00
parent 871277adde
commit 9ebf963be6
2 changed files with 38 additions and 0 deletions

View File

@@ -726,3 +726,13 @@ Hi there!
<img src="{{foo}}" />
<input value="{{foo}}" />
</template>
<template name="spacebars_test_event_handler_cleanup">
{{#if foo}}
{{>spacebars_test_event_handler_cleanup_sub}}
{{/if}}
</template>
<template name="spacebars_test_event_handler_cleanup_sub">
<div></div>
</template>

View File

@@ -2021,3 +2021,31 @@ Tinytest.add(
checkAttrs(" javascript:alert(1)", false);
}
);
Tinytest.add(
"spacebars - template - event handlers get cleaned up with template is removed",
function (test) {
var tmpl = Template.spacebars_test_event_handler_cleanup;
var subtmpl = Template.spacebars_test_event_handler_cleanup_sub;
var rv = new ReactiveVar(true);
tmpl.foo = function () {
return rv.get();
};
subtmpl.events({
"click/mouseover": function () { }
});
var div = renderToDiv(tmpl);
test.equal(div.$_uievents["click"].handlers.length, 1);
test.equal(div.$_uievents["mouseover"].handlers.length, 1);
rv.set(false);
Deps.flush();
test.equal(div.$_uievents["click"].handlers.length, 0);
test.equal(div.$_uievents["mouseover"].handlers.length, 0);
}
);