Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/wojtekmaj/async-array-utils. A collection of array-related async utilities.
array array-methods async promise utils
Something went wrong. Try again.
2.3 kB · 75 lines
JavaScript
at yarn-2
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576import asyncForEachStrict from './forEach_strict';import { doubleInputArr, inputArr, makePushDuplicate, makePushDuplicateInRandomTime,} from '../test-utils';
describe('asyncForEachStrict()', () => { it.skip('assertions below are valid for synchronous .forEach()', () => { const [arr, pushDuplicate] = makePushDuplicate(); const mapper = jest.fn().mockImplementation(pushDuplicate);
inputArr.forEach(mapper);
expect.assertions(1 + inputArr.length);
expect(mapper).toHaveBeenCalledTimes(inputArr.length); inputArr.forEach((el) => { expect(arr).toContain(el * 2); }); });
it('iterates through an array properly', async () => { const [arr, pushDuplicate] = makePushDuplicateInRandomTime(); const mapper = jest.fn().mockImplementation(pushDuplicate);
await asyncForEachStrict(inputArr, mapper);
expect.assertions(1 + inputArr.length);
expect(mapper).toHaveBeenCalledTimes(inputArr.length); inputArr.forEach((el) => { expect(arr).toContain(el * 2); }); });
it.skip('assertions below are valid for synchronous .forEach()', () => { const [arr, pushDuplicate] = makePushDuplicate(); const mapper = jest.fn().mockImplementation(pushDuplicate);
inputArr.forEach(mapper);
expect(mapper).toHaveBeenCalledTimes(inputArr.length); expect(arr).toEqual(doubleInputArr); });
it('iterates through an array properly with side effects', async () => { const [arr, pushDuplicate] = makePushDuplicateInRandomTime(); const mapper = jest.fn().mockImplementation(pushDuplicate);
await asyncForEachStrict(inputArr, mapper);
expect(mapper).toHaveBeenCalledTimes(inputArr.length); expect(arr).toEqual(doubleInputArr); });
it.skip('assertions below are valid for synchronous .forEach()', () => { const [, pushDuplicate] = makePushDuplicate(); const mapper = jest.fn().mockImplementation(pushDuplicate);
const result = inputArr.forEach(mapper);
expect(result).toBe(undefined); });
it('returns undefined', async () => { const [, pushDuplicate] = makePushDuplicate(); const mapper = jest.fn().mockImplementation(pushDuplicate);
const result = await asyncForEachStrict(inputArr, mapper);
expect(result).toBe(undefined); });});