From 1abd5fbb9c7230b105d1eafe2125e4e7628d78d4 Mon Sep 17 00:00:00 2001 From: Alex LaFroscia Date: Mon, 4 Feb 2019 23:53:13 -0800 Subject: [PATCH] fix: unsubscribe from decorator when the object is destroyed --- addon/decorators/subscribe.js | 2 +- tests/unit/decorators/subscribe-test.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/addon/decorators/subscribe.js b/addon/decorators/subscribe.js index 54f4d22..c8d1b02 100644 --- a/addon/decorators/subscribe.js +++ b/addon/decorators/subscribe.js @@ -69,7 +69,7 @@ export default function subscribe(observableKey) { } willDestroy() { - this.removeListener(observableKey, this, resetSubscription); + this.removeObserver(observableKey, this, resetSubscription); if (this[SUBSCRIPTION]) { this[SUBSCRIPTION].unsubscribe(); diff --git a/tests/unit/decorators/subscribe-test.js b/tests/unit/decorators/subscribe-test.js index 7b2b48d..1479d6f 100644 --- a/tests/unit/decorators/subscribe-test.js +++ b/tests/unit/decorators/subscribe-test.js @@ -129,5 +129,26 @@ module("Unit | Decorator | subscribe", function(hooks) { ); }); }); + + test("it un-subscribes when the object is destroyed", function(assert) { + this.scheduler.run(helpers => { + const i = SomeClass.create({ + observable: helpers.cold("--a--b", { + a: 1, + b: 2 + }) + }); + + this.scheduler.flush(); + + i.willDestroy(); + + assert.equal( + i.observable.subscriptions[0].unsubscribedFrame, + 5, + "Unsubscribed from the observable" + ); + }); + }); }); });