-
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.
test(toArray): add subscription assertions
Add subscription assertions on toArray tests.
- Loading branch information
Showing
1 changed file
with
32 additions
and
6 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,61 +1,87 @@ | ||
/* globals describe, it, expect, expectObservable, hot */ | ||
/* globals describe, it, expect, expectObservable, expectSubscriptions, cold, hot */ | ||
var Rx = require('../../dist/cjs/Rx'); | ||
var Observable = Rx.Observable; | ||
|
||
describe('toArray', function () { | ||
it('should be never when source is never', function () { | ||
var e1 = Observable.never(); | ||
var e1 = cold('-'); | ||
var e1subs = '^'; | ||
var expected = '-'; | ||
|
||
expectObservable(e1.toArray()).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
}); | ||
|
||
it('should be never when source is empty', function () { | ||
var e1 = Observable.empty(); | ||
var e1 = cold('|'); | ||
var e1subs = '(^!)'; | ||
var expected = '(w|)'; | ||
|
||
expectObservable(e1.toArray()).toBe(expected, { w: [] }); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
}); | ||
|
||
it('should be never when source doesn\'t complete', function () { | ||
var e1 = hot('--x--^--y--'); | ||
var expected = '-'; | ||
var e1subs = '^ '; | ||
var expected = '------'; | ||
|
||
expectObservable(e1.toArray()).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
}); | ||
|
||
it('should reduce observable without values into an array of length zero', function () { | ||
var e1 = hot('-x-^---|'); | ||
var e1subs = '^ !'; | ||
var expected = '----(w|)'; | ||
|
||
expectObservable(e1.toArray()).toBe(expected, { w: [] }); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
}); | ||
|
||
it('should reduce the a single value of an observable into an array', function () { | ||
var e1 = hot('-x-^--y--|'); | ||
var e1subs = '^ !'; | ||
var expected = '------(w|)'; | ||
|
||
expectObservable(e1.toArray()).toBe(expected, { w: ['y'] }); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
}); | ||
|
||
it('should reduce the values of an observable into an array', function () { | ||
var e1 = hot('-x-^--y--z--|'); | ||
var e1subs = '^ !'; | ||
var expected = '---------(w|)'; | ||
|
||
expectObservable(e1.toArray()).toBe(expected, { w: ['y', 'z'] }); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
}); | ||
|
||
it('should allow unsubscribing explicitly and early', function () { | ||
var e1 = hot('--a--b----c-----d----e---|'); | ||
var unsub = ' ! '; | ||
var e1subs = '^ ! '; | ||
var expected = '--------- '; | ||
|
||
expectObservable(e1.toArray(), unsub).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
}); | ||
|
||
it('should work with error', function () { | ||
var e1 = hot('-x-^--y--z--#', { x: 1, y: 2, z: 3 }, 'too bad'); | ||
var e1subs = '^ !'; | ||
var expected = '---------#'; | ||
|
||
expectObservable(e1.toArray()).toBe(expected, null, 'too bad'); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
}); | ||
|
||
it('should work with throw', function () { | ||
var e1 = Observable.throw(new Error('too bad')); | ||
var e1 = cold('#'); | ||
var e1subs = '(^!)'; | ||
var expected = '#'; | ||
|
||
expectObservable(e1.toArray()).toBe(expected, null, new Error('too bad')); | ||
expectObservable(e1.toArray()).toBe(expected); | ||
expectSubscriptions(e1.subscriptions).toBe(e1subs); | ||
}); | ||
}); |