|
1 | 1 | import { expect } from 'chai'; |
2 | | -import { mergeMap, map } from 'rxjs/operators'; |
| 2 | +import { mergeMap, map, delay } from 'rxjs/operators'; |
3 | 3 | import { asapScheduler, defer, Observable, from, of, timer } from 'rxjs'; |
4 | 4 | import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing'; |
5 | 5 | import { asInteropObservable } from '../helpers/interop-helper'; |
| 6 | +import { TestScheduler } from 'rxjs/testing'; |
| 7 | +import { observableMatcher } from '../helpers/observableMatcher'; |
6 | 8 |
|
7 | | -declare const type: Function; |
8 | 9 | declare const asDiagram: Function; |
9 | 10 |
|
10 | 11 | /** @test {mergeMap} */ |
11 | 12 | describe('mergeMap', () => { |
| 13 | + let rxTest: TestScheduler; |
| 14 | + |
| 15 | + // TODO: Convert the rest of these tests to use run mode! |
| 16 | + beforeEach(() => { |
| 17 | + rxTest = new TestScheduler(observableMatcher); |
| 18 | + }); |
| 19 | + |
12 | 20 | asDiagram('mergeMap(i => 10*i\u2014\u201410*i\u2014\u201410*i\u2014| )') |
13 | 21 | ('should map-and-flatten each item to an Observable', () => { |
14 | 22 | const e1 = hot('--1-----3--5-------|'); |
@@ -821,14 +829,27 @@ describe('mergeMap', () => { |
821 | 829 | }, 0); |
822 | 830 | }); |
823 | 831 |
|
824 | | - type('should support type signatures', () => { |
825 | | - let o: Observable<number>; |
826 | | - |
827 | | - /* tslint:disable:no-unused-variable */ |
828 | | - let a1: Observable<string> = o.pipe(mergeMap(x => x.toString())); |
829 | | - let a2: Observable<string> = o.pipe(mergeMap(x => x.toString(), 3)); |
830 | | - let a3: Observable<{ o: number; i: string; }> = o.pipe(mergeMap(x => x.toString(), (o, i) => ({ o, i }))); |
831 | | - let a4: Observable<{ o: number; i: string; }> = o.pipe(mergeMap(x => x.toString(), (o, i) => ({ o, i }), 3)); |
832 | | - /* tslint:enable:no-unused-variable */ |
| 832 | + // NOTE: From https://github.com/ReactiveX/rxjs/issues/5436 |
| 833 | + it('should properly handle errors from iterables that are processed after some async', () => { |
| 834 | + rxTest.run(({ cold, expectObservable }) => { |
| 835 | + const noXError = new Error('we do not allow x'); |
| 836 | + const source = cold('-----A------------B-----|', { A: ['o', 'o', 'o'], B: ['o', 'x', 'o']}); |
| 837 | + const expected = ' -----(ooo)--------(o#)'; |
| 838 | + const iterable = function* (data: string[]) { |
| 839 | + for (let d of data) { |
| 840 | + if (d === 'x') { |
| 841 | + throw noXError; |
| 842 | + } |
| 843 | + yield d; |
| 844 | + } |
| 845 | + }; |
| 846 | + const result = source.pipe( |
| 847 | + mergeMap(x => of(x).pipe( |
| 848 | + delay(0), |
| 849 | + mergeMap(iterable) |
| 850 | + )) |
| 851 | + ); |
| 852 | + expectObservable(result).toBe(expected, undefined, noXError); |
| 853 | + }); |
833 | 854 | }); |
834 | 855 | }); |
0 commit comments