Skip to content

Commit

Permalink
test(skipUntil): assert subscription/unsubscription
Browse files Browse the repository at this point in the history
Add tests to skipUntil that assert when its source and notifier get
subscribed and unsubscribed.
  • Loading branch information
Andre Medeiros authored and staltz committed Oct 30, 2015
1 parent c7b63d8 commit 97e2258
Showing 1 changed file with 88 additions and 17 deletions.
105 changes: 88 additions & 17 deletions spec/operators/skipUntil-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 97e2258

Please sign in to comment.