-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiterators.spec.ts
26 lines (20 loc) · 1 KB
/
iterators.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { AsyncCollection } from '../containers/AsyncCollection';
import { forEach, forEachAsync } from './iterators';
describe('core/helpers/iterators', () => {
test('forEach calls for every value of iterable collection', () => {
const collection = new Set(['one', 'two', 'three']);
const callback = jest.fn();
forEach(collection, callback);
expect(callback).toHaveBeenNthCalledWith(1, 'one', collection);
expect(callback).toHaveBeenNthCalledWith(2, 'two', collection);
expect(callback).toHaveBeenNthCalledWith(3, 'three', collection);
});
test('forEachAsync calls for every value of async iterable collection', async () => {
const collection = new AsyncCollection(['one', 'two', 'three']);
const callback = jest.fn();
await forEachAsync(collection, callback);
expect(callback).toHaveBeenNthCalledWith(1, 'one', collection);
expect(callback).toHaveBeenNthCalledWith(2, 'two', collection);
expect(callback).toHaveBeenNthCalledWith(3, 'three', collection);
});
});