Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { expect } from 'chai'; | ||
import { match, stub } from 'sinon'; | ||
|
||
import { filterMany } from '../../src/List'; | ||
|
||
describe('list utils', async () => { | ||
describe('filter many helper', async () => { | ||
it('should call the predicate with an item from each list', async () => { | ||
const cb = stub().returns(true); | ||
const results = filterMany(cb, [1], ['a']); | ||
|
||
expect(results.length).to.equal(1); | ||
expect(cb).to.have.callCount(1); | ||
expect(cb).to.have.been.calledWithMatch(match.number, match.string); | ||
}); | ||
|
||
it('should call the predicate for each slice', async () => { | ||
const data = [1, 2, 3, 4, 5]; | ||
const cb = stub().returns(true); | ||
const results = filterMany(cb, data); | ||
|
||
expect(results.length).to.equal(data.length); | ||
expect(cb).to.have.callCount(data.length); | ||
}); | ||
|
||
it('should keep slices that passed the predicate', async () => { | ||
const data = [1, 2, 3, 4, 5]; | ||
const cb = stub().returns(false); | ||
const results = filterMany(cb, data); | ||
|
||
expect(results.length).to.equal(0); | ||
expect(cb).to.have.callCount(data.length); | ||
}); | ||
}); | ||
}); |