Skip to content

Commit 1238557

Browse files
committed
Add unit tests for side effects in asyncSomeStrict
1 parent d29c001 commit 1238557

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/some_strict.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import asyncSomeStrict from './some_strict';
22

33
import {
4+
doubleInputArr,
45
inputArr,
56
largerThanTwo,
67
largerThanTwoInRandomTime,
78
largerThanOneHundred,
89
largerThanOneHundredInRandomTime,
10+
makePushDuplicate,
11+
makePushDuplicateInRandomTime,
912
} from '../test-utils';
1013

1114
const firstElementLargerThanTwo = inputArr.findIndex(largerThanTwo);
@@ -37,6 +40,26 @@ describe('asyncSomeStrict()', () => {
3740
});
3841
});
3942

43+
it('assertions below are valid for synchronous .map()', () => {
44+
const [arr, pushDuplicate] = makePushDuplicate();
45+
const mapper = jest.fn().mockImplementation(pushDuplicate);
46+
47+
inputArr.some(mapper);
48+
49+
expect(mapper).toHaveBeenCalledTimes(inputArr.length);
50+
expect(arr).toEqual(doubleInputArr);
51+
});
52+
53+
it('iterates through an array properly with side effects', async () => {
54+
const [arr, pushDuplicate] = makePushDuplicateInRandomTime();
55+
const mapper = jest.fn().mockImplementation(pushDuplicate);
56+
57+
await asyncSomeStrict(inputArr, mapper);
58+
59+
expect(mapper).toHaveBeenCalledTimes(inputArr.length);
60+
expect(arr).toEqual(doubleInputArr);
61+
});
62+
4063
it('assertions below are valid for synchronous .some()', () => {
4164
const mapper = jest.fn().mockImplementation(largerThanTwo);
4265

0 commit comments

Comments
 (0)