1
0
Fork 0
js-utils/test/utils/TestList.ts

36 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-08-01 15:01:00 +00:00
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);
});
});
});