Skip to content

Commit

Permalink
fix(elementAt): Reentrant errors no longer supercede results
Browse files Browse the repository at this point in the history
- adds test, fixed by changes to `take`.

Related ReactiveX#5487
  • Loading branch information
benlesh committed Dec 3, 2022
1 parent 0a7188a commit b5f35f8
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions spec/operators/elementAt-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { elementAt, mergeMap } from 'rxjs/operators';
import { elementAt, mergeMap, tap } from 'rxjs/operators';
import { TestScheduler } from 'rxjs/testing';
import { ArgumentOutOfRangeError, of, range, Observable } from 'rxjs';
import { ArgumentOutOfRangeError, of, range, Observable, Subject, merge } from 'rxjs';
import { observableMatcher } from '../helpers/observableMatcher';

/** @test {elementAt} */
Expand Down Expand Up @@ -178,4 +178,23 @@ describe('elementAt', () => {

expect(sideEffects).to.deep.equal([0, 1, 2]);
});

it('should not emit errors sent from the source *after* it found the first value in reentrant scenarios', () => {
testScheduler.run(({ cold, expectObservable, expectSubscriptions }) => {
const subject = new Subject();
const source = cold('-------a----b----c---|');
const expected = ' ------------(b|)';
const subs = ' ^-----------!';

const result = merge(source, subject).pipe(
elementAt(1),
tap(() => {
subject.error(new Error('reentrant shennanigans'));
})
);

expectObservable(result).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});
});
});

0 comments on commit b5f35f8

Please sign in to comment.