-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
466 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,193 @@ | ||
/* globals expect, it, describe, hot, cold, expectObservable, expectSubscriptions */ | ||
|
||
var Rx = require('../../dist/cjs/Rx'); | ||
var Observable = Rx.Observable; | ||
|
||
describe('Observable.race(...observables)', function () { | ||
it('should race a single observable', function () { | ||
var e1 = cold('---a-----b-----c----|'); | ||
var e1subs = '^ !'; | ||
var expected = '---a-----b-----c----|'; | ||
|
||
var result = Observable.race(e1); | ||
|
||
expectObservable(result).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
}); | ||
|
||
it('should race cold and cold', function () { | ||
var e1 = cold('---a-----b-----c----|'); | ||
var e1subs = '^ !'; | ||
var e2 = cold('------x-----y-----z----|'); | ||
var e2subs = '^ !'; | ||
var expected = '---a-----b-----c----|'; | ||
|
||
var result = Observable.race(e1, e2); | ||
|
||
expectObservable(result).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should race hot and hot', function () { | ||
var e1 = hot('---a-----b-----c----|'); | ||
var e1subs = '^ !'; | ||
var e2 = hot('------x-----y-----z----|'); | ||
var e2subs = '^ !'; | ||
var expected = '---a-----b-----c----|'; | ||
|
||
var result = Observable.race(e1, e2); | ||
|
||
expectObservable(result).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should race hot and cold', function () { | ||
var e1 = cold('---a-----b-----c----|'); | ||
var e1subs = '^ !'; | ||
var e2 = hot('------x-----y-----z----|'); | ||
var e2subs = '^ !'; | ||
var expected = '---a-----b-----c----|'; | ||
|
||
var result = Observable.race(e1, e2); | ||
|
||
expectObservable(result).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should race 2nd and 1st', function () { | ||
var e1 = cold('------x-----y-----z----|'); | ||
var e1subs = '^ !'; | ||
var e2 = cold('---a-----b-----c----|'); | ||
var e2subs = '^ !'; | ||
var expected = '---a-----b-----c----|'; | ||
|
||
var result = Observable.race(e1, e2); | ||
|
||
expectObservable(result).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should race emit and complete', function () { | ||
var e1 = cold('-----|'); | ||
var e1subs = '^ !'; | ||
var e2 = hot('------x-----y-----z----|'); | ||
var e2subs = '^ !'; | ||
var expected = '-----|'; | ||
|
||
var result = Observable.race(e1, e2); | ||
|
||
expectObservable(result).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should allow unsubscribing early and explicitly', function () { | ||
var e1 = cold('---a-----b-----c----|'); | ||
var e1subs = '^ !'; | ||
var e2 = hot('------x-----y-----z----|'); | ||
var e2subs = '^ !'; | ||
var expected = '---a-----b---'; | ||
var unsub = ' !'; | ||
|
||
var result = Observable.race(e1, e2); | ||
|
||
expectObservable(result, unsub).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should not break unsubscription chains when unsubscribed explicitly', function () { | ||
var e1 = hot('--a--^--b--c---d-| '); | ||
var e1subs = '^ ! '; | ||
var e2 = hot('---e-^---f--g---h-|'); | ||
var e2subs = '^ ! '; | ||
var expected = '---b--c--- '; | ||
var unsub = ' ! '; | ||
|
||
var result = Observable.race( | ||
e1.mergeMap(function (x) { return Observable.of(x); }), | ||
e2.mergeMap(function (x) { return Observable.of(x); }) | ||
).mergeMap(function (x) { return Observable.of(x); }); | ||
|
||
expectObservable(result, unsub).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should never emit when given non emitting sources', function () { | ||
var e1 = cold('---|'); | ||
var e2 = cold('---|'); | ||
var e1subs = '^ !'; | ||
var expected = '---|'; | ||
|
||
var source = Observable.race(e1, e2); | ||
|
||
expectObservable(source).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
}); | ||
|
||
it('should throw when error occurs mid stream', function () { | ||
var e1 = cold('---a-----#'); | ||
var e1subs = '^ !'; | ||
var e2 = cold('------x-----y-----z----|'); | ||
var e2subs = '^ !'; | ||
var expected = '---a-----#'; | ||
|
||
var result = Observable.race(e1, e2); | ||
|
||
expectObservable(result).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should throw when error occurs before a winner is found', function () { | ||
var e1 = cold('---#'); | ||
var e1subs = '^ !'; | ||
var e2 = cold('------x-----y-----z----|'); | ||
var e2subs = '^ !'; | ||
var expected = '---#'; | ||
|
||
var result = Observable.race(e1, e2); | ||
|
||
expectObservable(result).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('handle empty', function () { | ||
var e1 = cold('|'); | ||
var e1subs = '(^!)'; | ||
var expected = '|'; | ||
|
||
var source = Observable.race(e1); | ||
|
||
expectObservable(source).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
}); | ||
|
||
it('handle never', function () { | ||
var e1 = cold('-'); | ||
var e1subs = '^'; | ||
var expected = '-'; | ||
|
||
var source = Observable.race(e1); | ||
|
||
expectObservable(source).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
}); | ||
|
||
it('handle throw', function () { | ||
var e1 = cold('#'); | ||
var e1subs = '(^!)'; | ||
var expected = '#'; | ||
|
||
var source = Observable.race(e1); | ||
|
||
expectObservable(source).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* globals expect, it, describe, hot, cold, expectObservable, expectSubscriptions */ | ||
|
||
var Rx = require('../../dist/cjs/Rx'); | ||
var Observable = Rx.Observable; | ||
|
||
describe('...race(observables)', function () { | ||
it('should race cold and cold', function () { | ||
var e1 = cold('---a-----b-----c----|'); | ||
var e1subs = '^ !'; | ||
var e2 = cold('------x-----y-----z----|'); | ||
var e2subs = '^ !'; | ||
var expected = '---a-----b-----c----|'; | ||
|
||
var result = e1.race(e2); | ||
|
||
expectObservable(result).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should race hot and hot', function () { | ||
var e1 = hot('---a-----b-----c----|'); | ||
var e1subs = '^ !'; | ||
var e2 = hot('------x-----y-----z----|'); | ||
var e2subs = '^ !'; | ||
var expected = '---a-----b-----c----|'; | ||
|
||
var result = e1.race(e2); | ||
|
||
expectObservable(result).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should race hot and cold', function () { | ||
var e1 = cold('---a-----b-----c----|'); | ||
var e1subs = '^ !'; | ||
var e2 = hot('------x-----y-----z----|'); | ||
var e2subs = '^ !'; | ||
var expected = '---a-----b-----c----|'; | ||
|
||
var result = e1.race(e2); | ||
|
||
expectObservable(result).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should race 2nd and 1st', function () { | ||
var e1 = cold('------x-----y-----z----|'); | ||
var e1subs = '^ !'; | ||
var e2 = cold('---a-----b-----c----|'); | ||
var e2subs = '^ !'; | ||
var expected = '---a-----b-----c----|'; | ||
|
||
var result = e1.race(e2); | ||
|
||
expectObservable(result).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should race emit and complete', function () { | ||
var e1 = cold('-----|'); | ||
var e1subs = '^ !'; | ||
var e2 = hot('------x-----y-----z----|'); | ||
var e2subs = '^ !'; | ||
var expected = '-----|'; | ||
|
||
var result = e1.race(e2); | ||
|
||
expectObservable(result).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should allow unsubscribing early and explicitly', function () { | ||
var e1 = cold('---a-----b-----c----|'); | ||
var e1subs = '^ !'; | ||
var e2 = hot('------x-----y-----z----|'); | ||
var e2subs = '^ !'; | ||
var expected = '---a-----b---'; | ||
var unsub = ' !'; | ||
|
||
var result = e1.race(e2); | ||
|
||
expectObservable(result, unsub).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should not break unsubscription chains when unsubscribed explicitly', function () { | ||
var e1 = hot('--a--^--b--c---d-| '); | ||
var e1subs = '^ ! '; | ||
var e2 = hot('---e-^---f--g---h-|'); | ||
var e2subs = '^ ! '; | ||
var expected = '---b--c--- '; | ||
var unsub = ' ! '; | ||
|
||
var result = e1 | ||
.mergeMap(function (x) { return Observable.of(x); }) | ||
.race(e2) | ||
.mergeMap(function (x) { return Observable.of(x); }); | ||
|
||
expectObservable(result, unsub).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should never emit when given non emitting sources', function () { | ||
var e1 = cold('---|'); | ||
var e2 = cold('---|'); | ||
var e1subs = '^ !'; | ||
var expected = '---|'; | ||
|
||
var source = e1.race(e2); | ||
|
||
expectObservable(source).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
}); | ||
|
||
it('should throw when error occurs mid stream', function () { | ||
var e1 = cold('---a-----#'); | ||
var e1subs = '^ !'; | ||
var e2 = cold('------x-----y-----z----|'); | ||
var e2subs = '^ !'; | ||
var expected = '---a-----#'; | ||
|
||
var result = e1.race(e2); | ||
|
||
expectObservable(result).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
|
||
it('should throw when error occurs before a winner is found', function () { | ||
var e1 = cold('---#'); | ||
var e1subs = '^ !'; | ||
var e2 = cold('------x-----y-----z----|'); | ||
var e2subs = '^ !'; | ||
var expected = '---#'; | ||
|
||
var result = e1.race(e2); | ||
|
||
expectObservable(result).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
expectSubscriptions(e2.subscriptions).toBe(e2subs); | ||
}); | ||
}); |
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
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
Oops, something went wrong.