hunk.code_window:   "typings": "./index.d.ts",
     "main": "./index.js",
     "module": "../_esm5/ajax/index.js",
     "es2015": "../_esm2015/ajax/index.js"
   }
hunk.labels: keep keep keep replace keep
hunk.after_edit:   "es2015": "../_esm2015/ajax/index.js",
     "sideEffects": false
  
hunk.file_path: src/ajax/package.json
hunk.type: replace
file: import { expect } from 'chai';
  import * as Rx from '../../src/internal/Rx';
  import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing';
  
  declare function asDiagram(arg: string): Function;
  
  const Observable = Rx.Observable;
  
  /** @test {concatMapTo} */
  describe('Observable.prototype.concatMapTo', () => {
    asDiagram('concatMapTo( 10\u2014\u201410\u2014\u201410\u2014| )')
    ('should map-and-flatten each item to an Observable', () => {
      const e1 =    hot('--1-----3--5-------|');
      const e1subs =    '^                  !';
      const e2 =   cold('x-x-x|              ', {x: 10});
      const expected =  '--x-x-x-x-x-xx-x-x-|';
      const values = {x: 10};
  
      const result = e1.concatMapTo(e2);
  
      expectObservable(result).toBe(expected, values);
      expectSubscriptions(e1.subscriptions).toBe(e1subs);
    });
  
    it('should concatMapTo many outer values to many inner values', () => {
      const values = {i: 'foo', j: 'bar', k: 'baz', l: 'qux'};
      const e1 =     hot('-a---b---c---d---|                        ');
      const e1subs =     '^                                        !';
      const inner =  cold('--i-j-k-l-|                              ', values);
      const innersubs = [' ^         !                              ',
                       '           ^         !                    ',
                       '                     ^         !          ',
                       '                               ^         !'];
      const expected =   '---i-j-k-l---i-j-k-l---i-j-k-l---i-j-k-l-|';
  
      const result = e1.concatMapTo(inner);
  
      expectObservable(result).toBe(expected, values);
      expectSubscriptions(e1.subscriptions).toBe(e1subs);
      expectSubscriptions(inner.subscriptions).toBe(innersubs);
    });
  
    it('should handle an empty source', () => {
      const e1 = cold( '|');
      const e1subs =   '(^!)';
      const inner = cold('-1-2-3|');
      const innersubs: string[] = [];
      const expected = '|';
  
      const result = e1.concatMapTo(inner);
  
      expectObservable(result).toBe(expected);
      expectSubscriptions(e1.subscriptions).toBe(e1subs);
      expectSubscriptions(inner.subscriptions).toBe(innersubs);
    });
  
    it('should handle a never source', () => {
      const e1 = cold( '-');
      const e1subs =   '^';
      const inner = cold('-1-2-3|');
      const innersubs: string[] = [];
      const expected = '-';
  
      const result = e1.concatMapTo(inner);
  
      expectObservable(result).toBe(expected);
      expectSubscriptions(e1.subscriptions).toBe(e1subs);
      expectSubscriptions(inner.subscriptions).toBe(innersubs);
    });
  
    it('should error immediately if given a just-throw source', () => {
      const e1 = cold( '#');
      const e1subs =   '(^!)';
      const inner = cold('-1-2-3|');
      const innersubs: string[] = [];
      const expected = '#';
  
      const result = e1.concatMapTo(inner);
  
      expectObservable(result).toBe(expected);
      expectSubscriptions(e1.subscriptions).toBe(e1subs);
      expectSubscriptions(inner.subscriptions).toBe(innersubs);
    });
  
    it('should return a silenced version of the source if the mapped inner is empty', () => {
      const e1 =    cold('--a-b--c-|');
      const e1subs =     '^        !';
      const inner = cold('|');
      const innersubs = ['  (^!)     ',
                       '    (^!)   ',
                       '       (^!)'];
      const expected =   '---------|';
  
      const result = e1.concatMapTo(inner);
  
      expectObservable(result).toBe(expected);
      expectSubscriptions(e1.subscriptions).toBe(e1subs);
      expectSubscriptions(inner.subscriptions).toBe(innersubs);
    });
  
    it('should return a never if the mapped inner is never', () => {
      const e1 =    cold('--a-b--c-|');
      const e1subs =     '^         ';
      const inner = cold('-');
      const innersubs =  '  ^       ';
      const expected =   '----------';
  
      const result = e1.concatMapTo(inner);
  
      expectObservable(result).toBe(expected);
      expectSubscriptions(e1.subscriptions).toBe(e1subs);
      expectSubscriptions(inner.subscriptions).toBe(innersubs);
    });
  
    it('should propagate errors if the mapped inner is a just-throw Observable', () => {
      const e1 =    cold('--a-b--c-|');
      const e1subs =     '^ !       ';
      const inner = cold('#');
      const innersubs =  '  (^!)    ';
      const expected =   '--#';
  
      const result = e1.concatMapTo(inner);
  
      expectObservable(result).toBe(expected);
      expectSubscriptions(e1.subscriptions).toBe(e1subs);
      expectSubscriptions(inner.subscriptions).toBe(innersubs);
    });
  
    it('should concatMapTo many outer to many inner, complete late', () => {
      const values = {i: 'foo', j: 'bar', k: 'baz', l: 'qux'};
      const e1 =     hot('-a---b---c---d----------------------------------|');
      const e1subs =     '^                                               !';
      const inner =  cold('--i-j-k-l-|                                     ', values);
      const innersubs = [' ^         !                                     ',
                       '           ^         !                           ',
                       '                     ^         !                 ',
                       '                               ^         !       '];
      const expected =   '---i-j-k-l---i-j-k-l---i-j-k-l---i-j-k-l--------|';
  
      const result = e1.concatMapTo(inner);
  
      expectObservable(result).toBe(expected, values);
      expectSubscriptions(e1.subscriptions).toBe(e1subs);
      expectSubscriptions(inner.subscriptions).toBe(innersubs);
    });
  
    it('should concatMapTo many outer to many inner, outer never completes', () => {
      const values = {i: 'foo', j: 'bar', k: 'baz', l: 'qux'};
      const e1 =     hot('-a---b---c---d-----------------------------------');
      const e1subs =     '^                                                ';
      const inner =  cold('--i-j-k-l-|                                     ', values);
      const innersubs = [' ^         !                                     ',
                       '           ^         !                           ',
                       '                     ^         !                 ',
                       '                               ^         !       '];
      const expected =   '---i-j-k-l---i-j-k-l---i-j-k-l---i-j-k-l---------';
  
      const result = e1.concatMapTo(inner);
  
      expectObservable(result).toBe(expected, values);
      expectSubscriptions(e1.subscriptions).toBe(e1subs);
      expectSubscriptions(inner.subscriptions).toBe(innersubs);
    });
  
    it('should not break unsubscription chains when result is unsubscribed explicitly', () => {
      const values = {i: 'foo', j: 'bar', k: 'baz', l: 'qux'};
      const e1 =     hot('-a---b---c---d---| ');
      const e1subs =     '^                 !';
      const inner =  cold('--i-j-k-l-|       ', values);
      const innersubs = [' ^         !       ',
                       '           ^      !'];
      const expected =   '---i-j-k-l---i-j-k-';
      const unsub =      '                  !';
  
      const result = e1
        .mergeMap((x) => Observable.of(x))
        .concatMapTo(inner)
        .mergeMap((x) => Observable.of(x));
  
      expectObservable(result, unsub).toBe(expected, values);
      expectSubscriptions(e1.subscriptions).toBe(e1subs);
      expectSubscriptions(inner.subscriptions).toBe(innersubs);
    });
  
    it('should concatMapTo many outer to many inner, inner never completes', () => {
      const values = {i: 'foo', j: 'bar', k: 'baz', l: 'qux'};
      const e1 =     hot('-a---b---c---d---|');
      const e1subs =     '^                 ';
      const inner =  cold('--i-j-k-l-       ', values);
      const innersubs =  ' ^                ';
      const expected =   '---i-j-k-l--------';
  
      const result = e1.concatMapTo(inner);
  
      expectObservable(result).toBe(expected, values);
      expectSubscriptions(e1.subscriptions).toBe(e1subs);
      expectSubscriptions(inner.subscriptions).toBe(innersubs);
    });
  
    it('should concatMapTo many outer to many inner, and inner throws', () => {
      const values = {i: 'foo', j: 'bar', k: 'baz', l: 'qux'};
      const e1 =     hot('-a---b---c---d---|');
      const e1subs =     '^          !      ';
      const inner =  cold('--i-j-k-l-#      ', values);
      const innersubs =  ' ^         !      ';
      const expected =   '---i-j-k-l-#      ';
  
      const result = e1.concatMapTo(inner);
  
      expectObservable(result).toBe(expected, values);
      expectSubscriptions(e1.subscriptions).toBe(e1subs);
      expectSubscriptions(inner.subscriptions).toBe(innersubs);
    });
  
    it('should concatMapTo many outer to many inner, and outer throws', () => {
      const values = {i: 'foo', j: 'bar', k: 'baz', l: 'qux'};
      const e1 =     hot('-a---b---c---d---#');
      const e1subs =     '^                !';
      const inner =  cold('--i-j-k-l-|      ', values);
      const innersubs = [' ^         !      ',
                       '           ^     !'];
      const expected =   '---i-j-k-l---i-j-#';
  
      const result = e1.concatMapTo(inner);
  
      expectObservable(result).toBe(expected, values);
      expectSubscriptions(e1.subscriptions).toBe(e1subs);
      expectSubscriptions(inner.subscriptions).toBe(innersubs);
    });
  
    it('should concatMapTo many outer to many inner, both inner and outer throw', () => {
      const values = {i: 'foo', j: 'bar', k: 'baz', l: 'qux'};
      const e1 =     hot('-a---b---c---d---#');
      const e1subs =     '^          !      ';
      const inner =  cold('--i-j-k-l-#      ', values);
      const innersubs =  ' ^         !      ';
      const expected =   '---i-j-k-l-#      ';
  
      const result = e1.concatMapTo(inner);
  
      expectObservable(result).toBe(expected, values);
      expectSubscriptions(e1.subscriptions).toBe(e1subs);
      expectSubscriptions(inner.subscriptions).toBe(innersubs);
    });
  
    it('should concatMapTo many outer to an array', () => {
      const e1 =   hot('2-----4--------3--------2-------|');
      const expected = '(0123)(0123)---(0123)---(0123)--|';
  
      const result = e1.concatMapTo(['0', '1', '2', '3']);
  
      expectObservable(result).toBe(expected);
    });
  
    it('should concatMapTo many outer to inner arrays, and outer throws', () => {
      const e1 =   hot('2-----4--------3--------2-------#');
      const expected = '(0123)(0123)---(0123)---(0123)--#';
  
      const result = e1.concatMapTo(['0', '1', '2', '3']);
  
      expectObservable(result).toBe(expected);
    });
  
    it('should mergeMap many outer to inner arrays, outer unsubscribed early', () => {
      const e1 =   hot('2-----4--------3--------2-------|');
      const unsub =    '             !';
      const expected = '(0123)(0123)--';
  
      const result = e1.concatMapTo(['0', '1', '2', '3']);
  
      expectObservable(result, unsub).toBe(expected);
    });
  
    it('should map values to constant resolved promises and concatenate', (done: MochaDone) => {
      const source = Rx.Observable.from([4, 3, 2, 1]);
  
      const results: number[] = [];
      source.concatMapTo(Observable.from(Promise.resolve(42))).subscribe(
        (x) => {
          results.push(x);
        },
        (err) => {
          done(new Error('Subscriber error handler not supposed to be called.'));
        },
        () => {
          expect(results).to.deep.equal([42, 42, 42, 42]);
          done();
        });
    });
  
    it('should map values to constant rejected promises and concatenate', (done) => {
      const source = Rx.Observable.from([4, 3, 2, 1]);
  
      source.concatMapTo(Observable.from(Promise.reject(42))).subscribe(
        (x) => {
          done(new Error('Subscriber next handler not supposed to be called.'));
        },
        (err) => {
          expect(err).to.equal(42);
          done();
        },
        () => {
          done(new Error('Subscriber complete handler not supposed to be called.'));
        });
    });
  });
  