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.1 kB · 71 lines
JavaScript
at yarn-2
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172import asyncSomeStrict from './some_strict';
import { inputArr, largerThanTwo, largerThanTwoInRandomTime, largerThanOneHundred, largerThanOneHundredInRandomTime,} from '../test-utils';
const firstElementLargerThanTwo = inputArr.findIndex(largerThanTwo);
describe('asyncSomeStrict()', () => { it('assertions below are valid for synchronous .some()', () => { const mapper = jest.fn().mockImplementation(largerThanTwo);
inputArr.some(mapper);
expect.assertions(1 + firstElementLargerThanTwo);
expect(mapper).toHaveBeenCalledTimes(firstElementLargerThanTwo + 1); inputArr.slice(0, firstElementLargerThanTwo).forEach((el, idx) => { expect(mapper).toHaveBeenCalledWith(el, idx, inputArr); }); });
it('iterates over values properly', async () => { const mapper = jest.fn().mockImplementation(largerThanTwoInRandomTime);
await asyncSomeStrict(inputArr, mapper);
expect.assertions(1 + firstElementLargerThanTwo);
expect(mapper).toHaveBeenCalledTimes(firstElementLargerThanTwo + 1); inputArr.slice(0, firstElementLargerThanTwo).forEach((el, idx) => { expect(mapper).toHaveBeenCalledWith(el, idx, inputArr); }); });
it('assertions below are valid for synchronous .some()', () => { const mapper = jest.fn().mockImplementation(largerThanTwo);
const result = inputArr.some(mapper);
expect(result).toEqual(true); });
it('returns truthy result properly', async () => { const mapper = jest.fn().mockImplementation(largerThanTwoInRandomTime);
const result = await asyncSomeStrict(inputArr, mapper);
expect(result).toEqual(true); });
it('assertions below are valid for synchronous .some()', () => { const mapper = jest.fn().mockImplementation(largerThanOneHundred);
const result = inputArr.some(mapper);
expect(result).toEqual(false); });
it('returns falsy result properly', async () => { const mapper = jest.fn().mockImplementation(largerThanOneHundredInRandomTime);
const result = await asyncSomeStrict(inputArr, mapper);
expect(result).toEqual(false); });});