From 0cf7cb36c4c1bed82ebfe366b49c04642af9c08f Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 29 Jul 2019 10:58:27 +0200 Subject: [PATCH] add failing test for unsubscribe using wrong handler --- src/observable/BaseObservableCollection.js | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/observable/BaseObservableCollection.js b/src/observable/BaseObservableCollection.js index 17ea3c82..87e7c77b 100644 --- a/src/observable/BaseObservableCollection.js +++ b/src/observable/BaseObservableCollection.js @@ -30,3 +30,26 @@ export default class BaseObservableCollection { // Add iterator over handlers here } + +export function tests() { + class Collection extends BaseObservableCollection { + constructor() { + super(); + this.firstSubscribeCalls = 0; + this.firstUnsubscribeCalls = 0; + } + onSubscribeFirst() { this.firstSubscribeCalls += 1; } + onUnsubscribeLast() { this.firstUnsubscribeCalls += 1; } + } + + return { + test_unsubscribe(assert) { + const c = new Collection(); + const subscription = c.subscribe({}); + // unsubscribe + subscription(); + assert.equal(c.firstSubscribeCalls, 1); + assert.equal(c.firstUnsubscribeCalls, 1); + } + } +}