Skip to content

Commit 71d0bdd

Browse files
authored
Merge pull request #277 from canjs/276-test-and-partial-fix
DO NOT MERGE: partial fix and test for #276
2 parents 3d69b8c + 7679975 commit 71d0bdd

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

can-component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ function getSetupFunctionForComponentVM(componentInitVM) {
206206
onCompleteBindings.push(canBinding.start.bind(canBinding));
207207

208208
// We’ll want to turn off the bindings when the component is destroyed
209-
onTeardowns.push(canBinding.stop);
209+
onTeardowns.push(canBinding.stop.bind(canBinding));
210210

211211
} else {
212212
// Can’t get or set the value, so assume it’s not an observable

test/component-in-stache-test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var Component = require("can-component");
22
var SimpleMap = require("can-simple-map");
3+
var SimpleObservable = require("can-simple-observable");
34
var stache = require("can-stache");
45
var canReflect = require("can-reflect");
56
var QUnit = require("steal-qunit");
@@ -75,3 +76,39 @@ QUnit.test("wrapped in a conditional", function (assert) {
7576
templateVM.set("showComponent", false);
7677
assert.equal(fragment.textContent, "", "fragment ends without content");
7778
});
79+
80+
QUnit.test("Component can be removed from the page", 2, function(){
81+
82+
var ToBeRemoved = Component.extend({
83+
tag: "to-be-removed",
84+
view: "{{prop}}",
85+
ViewModel: {
86+
prop: "string"
87+
},
88+
events: {
89+
"{element} beforeremove": function(){
90+
QUnit.ok(true, "torn down");
91+
}
92+
}
93+
});
94+
95+
var prop = new SimpleObservable(3);
96+
97+
var toBeRemoved = new ToBeRemoved({
98+
viewModel: {
99+
prop: prop
100+
}
101+
});
102+
103+
var show = new SimpleObservable(true);
104+
105+
var template = stache("<div>{{# if(show) }} {{{toBeRemoved}}} {{/ if}}</div>");
106+
107+
template({
108+
show: show,
109+
toBeRemoved: toBeRemoved
110+
});
111+
112+
show.set(false);
113+
QUnit.ok(true, "got here without an error");
114+
});

0 commit comments

Comments
 (0)