Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosrberto committed Apr 2, 2018
1 parent 2693acb commit d407d30
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/LazyList.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default class LazyList {
const { list, operations } = this;
const listLength = list.length;
const operationsLength = operations.length;
const { type: lastOperationType } = operations[operationsLength - 1];
const result = [];
let reducerAcc;

Expand Down Expand Up @@ -90,12 +91,12 @@ export default class LazyList {
}
}

if (nextItem.valid) {
if (lastOperationType !== LIST_OPERATIONS.REDUCE && nextItem.valid) {
result.push(nextItem.value);
}
}

if (reducerAcc) {
if (lastOperationType === LIST_OPERATIONS.REDUCE) {
return reducerAcc;
}

Expand Down
2 changes: 2 additions & 0 deletions src/LazyList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe('LazyList.map', () => {
describe('LazyList.filter', () => {
it('should filter value correctly', () => {
expect(lazy([0, 1, 2]).filter(v => v > 0).value()).toEqual([1, 2]);
expect(lazy([0, true, false]).filter(v => !!v).value()).toEqual([true]);
expect(lazy([
{ name: 'Joe', age: 3 },
{ name: 'Spike', age: 16 },
Expand All @@ -103,6 +104,7 @@ describe('LazyList.filter', () => {
describe('LazyList.reduce', () => {
it('should reduce to correctly value', () => {
expect(lazy([1, 2, 3]).reduce((a, b) => a + b)).toEqual(6);
expect(lazy([0, 0]).reduce((a, b) => a + b)).toEqual(0);
});

it('should reduce to correctly value when provide initial value', () => {
Expand Down

0 comments on commit d407d30

Please sign in to comment.