forked from ReactiveX/rxjs
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(takeUntil): assert subscription/unsubscription
Add tests on takeUntil that assert when its source and notifier get subscribed and unsubscribed.
- Loading branch information
Andre Medeiros
committed
Oct 23, 2015
1 parent
2c95891
commit ba997c6
Showing
1 changed file
with
83 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,161 @@ | ||
/* globals describe, it, expect, hot, cold, expectObservable */ | ||
/* globals describe, it, expect, hot, cold, expectObservable, expectSubscriptions */ | ||
var Rx = require('../../dist/cjs/Rx'); | ||
var Observable = Rx.Observable; | ||
|
||
describe('Observable.prototype.takeUntil()', function () { | ||
it('should take values until another observable emits', function () { | ||
it('should take values until notifier emits', function () { | ||
var e1 = hot('--a--b--c--d--e--f--g--|'); | ||
var e2 = hot('-------------z--|'); | ||
var expected = '--a--b--c--d-|'; | ||
var e1subs = '^ ! '; | ||
var e2 = hot('-------------z--| '); | ||
var e2subs = '^ ! '; | ||
var expected = '--a--b--c--d-| '; | ||
|
||
expectObservable(e1.takeUntil(e2)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should take values and raises error until another observable raises error', function () { | ||
it('should take values and raises error when notifier raises error', function () { | ||
var e1 = hot('--a--b--c--d--e--f--g--|'); | ||
var e2 = hot('-------------#--|'); | ||
var expected = '--a--b--c--d-#'; | ||
var e1subs = '^ ! '; | ||
var e2 = hot('-------------#--| '); | ||
var e2subs = '^ ! '; | ||
var expected = '--a--b--c--d-# '; | ||
|
||
expectObservable(e1.takeUntil(e2)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should take all values when another observable is empty', function () { | ||
it('should take all values when notifier is empty', function () { | ||
var e1 = hot('--a--b--c--d--e--f--g--|'); | ||
var e2 = hot('-------------|'); | ||
var e1subs = '^ !'; | ||
var e2 = hot('-------------| '); | ||
var e2subs = '^ ! '; | ||
var expected = '--a--b--c--d--e--f--g--|'; | ||
|
||
expectObservable(e1.takeUntil(e2)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should take all values when another observable does not completes', function () { | ||
it('should take all values when notifier does not complete', function () { | ||
var e1 = hot('--a--b--c--d--e--f--g--|'); | ||
var e1subs = '^ !'; | ||
var e2 = hot('-'); | ||
var e2subs = '^ !'; | ||
var expected = '--a--b--c--d--e--f--g--|'; | ||
|
||
expectObservable(e1.takeUntil(e2)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should completes when another observable emits if source observable does not completes', function () { | ||
it('should complete when notifier emits if source observable does not complete', function () { | ||
var e1 = hot('-'); | ||
var e1subs = '^ !'; | ||
var e2 = hot('--a--b--|'); | ||
var e2subs = '^ !'; | ||
var expected = '--|'; | ||
|
||
expectObservable(e1.takeUntil(e2)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should raises error when another observable raises error if source observable does not completes', function () { | ||
it('should raise error when notifier raises error if source observable does not complete', function () { | ||
var e1 = hot('-'); | ||
var e1subs = '^ !'; | ||
var e2 = hot('--#'); | ||
var e2subs = '^ !'; | ||
var expected = '--#'; | ||
|
||
expectObservable(e1.takeUntil(e2)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should not completes when another observable is empty if source observable does not completes', function () { | ||
it('should not complete when notifier is empty if source observable does not complete', function () { | ||
var e1 = hot('-'); | ||
var e1subs = '^'; | ||
var e2 = hot('--|'); | ||
var expected = '-'; | ||
var e2subs = '^ !'; | ||
var expected = '---'; | ||
|
||
expectObservable(e1.takeUntil(e2)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should not completes when source and another observable does not complete', function () { | ||
it('should not complete when source and notifier do not complete', function () { | ||
var e1 = hot('-'); | ||
var e1subs = '^'; | ||
var e2 = hot('-'); | ||
var e2subs = '^'; | ||
var expected = '-'; | ||
|
||
expectObservable(e1.takeUntil(e2)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should completes when another observable emits before source observable emits', function () { | ||
it('should complete when notifier emits before source observable emits', function () { | ||
var e1 = hot('----a--|'); | ||
var e2 = hot('--x'); | ||
var expected = '--|'; | ||
var e1subs = '^ ! '; | ||
var e2 = hot('--x '); | ||
var e2subs = '^ ! '; | ||
var expected = '--| '; | ||
|
||
expectObservable(e1.takeUntil(e2)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should raises error if source raises error before another observable emits', function () { | ||
var e1 = hot('--a--b--c--d--#'); | ||
it('should raise error if source raises error before notifier emits', function () { | ||
var e1 = hot('--a--b--c--d--# '); | ||
var e1subs = '^ ! '; | ||
var e2 = hot('----------------a--|'); | ||
var expected = '--a--b--c--d--#'; | ||
var e2subs = '^ ! '; | ||
var expected = '--a--b--c--d--# '; | ||
|
||
expectObservable(e1.takeUntil(e2)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should raise error immediately if source throws', function () { | ||
var value = 'error'; | ||
var e1 = Observable.throw(value); | ||
var e1 = cold( '#'); | ||
var e1subs = '(^!)'; | ||
var e2 = hot('--x'); | ||
var e2subs = '(^!)'; | ||
var expected = '#'; | ||
|
||
expectObservable(e1.takeUntil(e2)).toBe(expected, null, value); | ||
expectObservable(e1.takeUntil(e2)).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should dispose source observable if another source observable emits before source emits', function () { | ||
var signaled = false; | ||
var e1 = hot('---a---|').do(function () { signaled = true; }); | ||
var e2 = hot('-x--|'); | ||
var expected = '-|'; | ||
it('should dispose source observable if notifier emits before source emits', function () { | ||
var e1 = hot('---a---|'); | ||
var e1subs = '^ ! '; | ||
var e2 = hot('--x-| '); | ||
var e2subs = '^ ! '; | ||
var expected = '--| '; | ||
|
||
expectObservable(e1.takeUntil(e2)).toBe(expected); | ||
expect(signaled).toBe(false); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should dispose another observable if source observable completes', function () { | ||
var signaled = false; | ||
var e1 = hot('--a--|'); | ||
var e2 = hot('-------x--|').do(function (x) { signaled = true; }); | ||
var expected = '--a--|'; | ||
it('should dispose notifier if source observable completes', function () { | ||
var e1 = hot('--a--| '); | ||
var e1subs = '^ ! '; | ||
var e2 = hot('-------x--|'); | ||
var e2subs = '^ ! '; | ||
var expected = '--a--| '; | ||
|
||
expectObservable(e1.takeUntil(e2)).toBe(expected); | ||
expect(signaled).toBe(false); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
}); |