Skip to content

Commit

Permalink
fix(every): index properly increments in predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh committed Oct 2, 2020
1 parent d3a083f commit 5686f83
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions spec/operators/every-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ describe('every operator', () => {

});

it('should increment index on each call to the predicate', () => {
const indices: number[] = [];
of(1, 2, 3, 4).pipe(
every((_, i) => {
indices.push(i);
return true;
})
).subscribe();

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

it('should accept thisArg with array observables', () => {
const thisArg = {};

Expand Down
2 changes: 1 addition & 1 deletion src/internal/operators/every.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function every<T>(
new OperatorSubscriber(
subscriber,
(value) => {
if (!predicate.call(thisArg, value, index, source)) {
if (!predicate.call(thisArg, value, index++, source)) {
subscriber.next(false);
subscriber.complete();
}
Expand Down

0 comments on commit 5686f83

Please sign in to comment.