Skip to content

Commit

Permalink
test(toArray): add subscription assertions
Browse files Browse the repository at this point in the history
Add subscription assertions on toArray tests.
  • Loading branch information
staltz authored and kwonoj committed Nov 30, 2015
1 parent 14e2e25 commit a687695
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions spec/operators/to-array-spec.js
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);
});
});

0 comments on commit a687695

Please sign in to comment.