From 97e2258094b441e8f3b967b1d7d4381ee834ecf0 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Fri, 23 Oct 2015 11:02:18 +0300 Subject: [PATCH] test(skipUntil): assert subscription/unsubscription Add tests to skipUntil that assert when its source and notifier get subscribed and unsubscribed. --- spec/operators/skipUntil-spec.js | 105 ++++++++++++++++++++++++++----- 1 file changed, 88 insertions(+), 17 deletions(-) diff --git a/spec/operators/skipUntil-spec.js b/spec/operators/skipUntil-spec.js index f4fa494fbe..41106da5fc 100644 --- a/spec/operators/skipUntil-spec.js +++ b/spec/operators/skipUntil-spec.js @@ -4,126 +4,197 @@ var Observable = Rx.Observable; describe('Observable.prototype.skipUntil()', function () { it('should skip values until another observable notifies', function () { - var e1 = hot('--a--b--c--d--e--|'); - var skip = hot('-------------x--|'); - var expected = ('--------------e--|'); + var e1 = hot('--a--b--c--d--e----|'); + var e1subs = '^ !'; + var skip = hot('-------------x--| '); + var skipSubs = '^ ! '; + var expected = ('--------------e----|'); expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(skip.subscriptions).toBe(skipSubs); }); it('should emit element only after another observable emits', function () { var e1 = hot('--a--b--c--d--e--|'); - var skip = hot('-----------x----|'); + var e1subs = '^ !'; + var skip = hot('-----------x----| '); + var skipSubs = '^ ! '; var expected = ('--------------e--|'); expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(skip.subscriptions).toBe(skipSubs); }); it('should skip value and raises error until another observable raises error', function () { var e1 = hot('--a--b--c--d--e--|'); - var skip = hot('-------------#'); - var expected = '-------------#'; + var e1subs = '^ ! '; + var skip = hot('-------------# '); + var skipSubs = '^ ! '; + var expected = '-------------# '; expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(skip.subscriptions).toBe(skipSubs); }); it('should skip all element when another observable does not emit and completes early', function () { var e1 = hot('--a--b--c--d--e--|'); - var skip = hot('------------|'); + var e1subs = '^ !'; + var skip = hot('------------| '); + var skipSubs = '^ ! '; var expected = '-----------------|'; expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(skip.subscriptions).toBe(skipSubs); }); it('should skip all element when another observable is empty', function () { var e1 = hot('--a--b--c--d--e--|'); - var skip = Observable.empty(); + var e1subs = '^ !'; + var skip = cold('|'); + var skipSubs = '(^!)'; var expected = '-----------------|'; expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(skip.subscriptions).toBe(skipSubs); + }); + + it('should keep subscription to source, to wait for its eventual complete', function () { + var e1 = hot('------------------------------|'); + var e1subs = '^ !'; + var skip = hot('-------| '); + var skipSubs = '^ ! '; + var expected = '------------------------------|'; + + expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(skip.subscriptions).toBe(skipSubs); }); it('should not complete if source observable does not complete', function () { var e1 = hot('-'); + var e1subs = '^'; var skip = hot('-------------x--|'); + var skipSubs = '^ !'; var expected = '-'; expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(skip.subscriptions).toBe(skipSubs); }); it('should not complete if source observable never completes', function () { - var e1 = Observable.never(); + var e1 = cold( '-'); + var e1subs = '^'; var skip = hot('-------------x--|'); + var skipSubs = '^ !'; var expected = '-'; expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(skip.subscriptions).toBe(skipSubs); }); it('should raise error if source does not completes when another observable raises error', function () { var e1 = hot('-'); + var e1subs = '^ !'; var skip = hot('-------------#'); + var skipSubs = '^ !'; var expected = '-------------#'; expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(skip.subscriptions).toBe(skipSubs); }); it('should raise error if source never completes when another observable raises error', function () { - var e1 = Observable.never(); + var e1 = cold( '-'); + var e1subs = '^ !'; var skip = hot('-------------#'); + var skipSubs = '^ !'; var expected = '-------------#'; expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(skip.subscriptions).toBe(skipSubs); }); it('should skip all element and does not complete when another observable never completes', function () { - var e1 = hot('--a--b--c--d--e--|'); - var skip = Observable.never(); - var expected = '-'; + var e1 = hot( '--a--b--c--d--e--|'); + var e1subs = '^ !'; + var skip = cold('-'); + var skipSubs = '^ !'; + var expected = '-'; expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(skip.subscriptions).toBe(skipSubs); }); it('should skip all element and does not complete when another observable does not completes', function () { var e1 = hot('--a--b--c--d--e--|'); + var e1subs = '^ !'; var skip = hot('-'); + var skipSubs = '^ !'; var expected = '-'; expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(skip.subscriptions).toBe(skipSubs); }); it('should skip all element and does not complete when another observable completes after source', function () { var e1 = hot('--a--b--c--d--e--|'); + var e1subs = '^ !'; var skip = hot('------------------------|'); - var expected = '-'; + var skipSubs = '^ !'; + var expected = '------------------'; expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(skip.subscriptions).toBe(skipSubs); }); it('should not completes if source does not completes when another observable does not emit', function () { var e1 = hot('-'); + var e1subs = '^'; var skip = hot('--------------|'); + var skipSubs = '^ !'; var expected = '-'; expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(skip.subscriptions).toBe(skipSubs); }); it('should not completes if source and another observable both does not complete', function () { var e1 = hot('-'); + var e1subs = '^'; var skip = hot('-'); + var skipSubs = '^'; var expected = '-'; expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + expectSubscriptions(skip.subscriptions).toBe(skipSubs); }); it('should skip all element when another observable unsubscribed early before emit', function () { - var e1 = hot('--a--b--c--d--e--|'); - var skip = hot('-------------x--|'); - var expected = '-'; + var e1 = hot( '--a--b--c--d--e--|'); + var e1subs = ['^ !', + '^ !']; // for the explicit subscribe some lines below + var skip = hot( '-------------x--|'); + var expected = '-'; e1.subscribe(function () { skip.unsubscribe(); }); expectObservable(e1.skipUntil(skip)).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); }); }); \ No newline at end of file