Skip to content

Commit 3399167

Browse files
author
mmasterson
committed
#17 Failing test for unsubscribing on destroy
1 parent 893ffb9 commit 3399167

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

force-app/test/default/staticresources/reduxTests.resource

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,42 @@ describe("Redux Tests", function() {
198198
done.fail(e);
199199
});
200200
});
201+
202+
it('unsubscribes when destroyed', function(done) {
203+
var renderInto = document.getElementById("renderTestComponents");
204+
$T.createComponent("c:TestReduxContainer", {}, renderInto)
205+
.then(function(component) {
206+
207+
var redux = component.find("store");
208+
209+
var toggle = false;
210+
function toggleReducer(state, action) {
211+
toggle = !toggle;
212+
if(toggle) {
213+
return "Toggle is True";
214+
} else {
215+
return "Toggle is False";
216+
}
217+
}
218+
219+
redux.createStore("toggle", toggleReducer);
220+
221+
var mapStateToAttributes = {
222+
"v.message": "toggle"
223+
};
224+
225+
redux.connect(mapStateToAttributes, component);
226+
expect(component.get("v.message")).toBe("Toggle is True");
227+
component.dispatch({type: "INCREMENT"});
228+
expect(component.get("v.message")).toBe("Toggle is False");
229+
component.destroy();
230+
component.dispatch({type: "INCREMENT"});
231+
expect(component.get("v.message")).toBe("Toggle is True");
232+
done();
233+
}).catch(function(e) {
234+
done.fail(e);
235+
});
236+
});
201237
});
202238

203239
describe('Test Queueing', function() {

force-app/test/default/staticresources/testutil.resource

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@
114114
while (cmpsToCleanup.length) {
115115
var globalId = cmpsToCleanup.shift();
116116
var cmp = $A.getComponent(globalId);
117-
cmp.destroy();
117+
if(cmp && cmp.isValid()) {
118+
cmp.destroy();
119+
}
118120
}
119121
}
120122

0 commit comments

Comments
 (0)