Skip to content

Commit

Permalink
test(mergeMap): unsubscribe-related marble tests
Browse files Browse the repository at this point in the history
Using the new unsubscription marble diagram feature in expectObservable
to cover more unsubscribe-related tests from RxJS 4.
  • Loading branch information
Andre Medeiros authored and benlesh committed Sep 30, 2015
1 parent ffb0bb9 commit 4d973a3
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion spec/operators/merge-map-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ describe('Observable.prototype.mergeMap()', function () {
.toBe(expected, values);
});

it('should mergeMap many outer to many inner, outer never completes', function () {
var values = {i: 'foo', j: 'bar', k: 'baz', l: 'qux'};
var e1 = hot('-a-------b-------c-------d-------e---------------f');
var inner = cold('----i---j---k---l---|', values);
var unsub = '-------------------------------------------------------!';
var expected = '-----i---j---(ki)(lj)(ki)(lj)(ki)(lj)(ki)(lj)k---l---i-';

var source = e1.mergeMap(function(value) { return inner; });
expectObservable(source, unsub).toBe(expected, values);
});

it('should mergeMap many outer to many inner, inner never completes', function () {
var values = {i: 'foo', j: 'bar', k: 'baz', l: 'qux'};
var e1 = hot('-a-------b-------c-------d-------|');
Expand Down Expand Up @@ -277,6 +288,26 @@ describe('Observable.prototype.mergeMap()', function () {
})).toBe(expected);
});

it('should mergeMap many complex, all inners finite, outer is unsubscribed', function () {
var a = cold( '-#' );
var b = cold( '-#' );
var c = cold( '-2--3--4--5------------------6-|' );
var d = cold( '-----------2--3|' );
var e = cold( '-1--------2--3-----4--5--------|');
var f = cold( '--|' );
var g = cold( '---1-2|' );
var e1 = hot('-a-b--^-c-----d------e----------------f-----g|' );
var unsub = '------------------------------!' ;
var expected = '---2--3--4--5---1--2--3--2--3--';

var observableLookup = { a: a, b: b, c: c, d: d, e: e, f: f, g: g };
var source = e1.mergeMap(function (value) {
return observableLookup[value];
});

expectObservable(source, unsub).toBe(expected);
});

it('should mergeMap many complex, all inners finite, project throws', function () {
var a = cold( '-#' );
var b = cold( '-#' );
Expand Down Expand Up @@ -357,6 +388,32 @@ describe('Observable.prototype.mergeMap()', function () {
expectObservable(source).toBe(expected);
});

it('should mergeMap many outer to inner arrays, outer gets unsubscribed', function () {
var e1 = hot('2-----4--------3--------2-------|');
var unsub = '-------------!';
var expected = '(22)--(4444)--';

var source = e1.mergeMap(function (value) {
return arrayRepeat(value, value);
});

expectObservable(source, unsub).toBe(expected);
});

it('should mergeMap many outer to inner arrays, resultSelector, outer unsubscribed', function () {
var e1 = hot('2-----4--------3--------2-------|');
var unsub = '-------------!';
var expected = '(44)--(8888)--';

var source = e1.mergeMap(function (value) {
return arrayRepeat(value, value);
}, function (x, y) {
return String(parseInt(x) + parseInt(y));
});

expectObservable(source, unsub).toBe(expected);
});

it('should mergeMap many outer to inner arrays, project throws', function () {
var e1 = hot('2-----4--------3--------2-------|');
var expected = '(22)--(4444)---#';
Expand Down Expand Up @@ -442,4 +499,4 @@ describe('Observable.prototype.mergeMap()', function () {

expect(completed).toBe(true);
});
});
});

0 comments on commit 4d973a3

Please sign in to comment.