forked from remeda/remeda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flatMap.test.ts
35 lines (32 loc) · 980 Bytes
/
flatMap.test.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
27
28
29
30
31
32
33
34
35
import { find } from './find';
import { flatMap } from './flatMap';
import { pipe } from './pipe';
import { createCounter } from './_counter';
describe('data_first', () => {
it('flatMap', () => {
const result = flatMap([1, 2] as const, x => [x * 2, x * 3]);
expect(result).toEqual([2, 3, 4, 6]);
});
});
describe('data_last', () => {
it('flatMap', () => {
const result = flatMap((x: number) => [x * 2, x * 3])([1, 2]);
expect(result).toEqual([2, 3, 4, 6]);
});
describe('pipe', () => {
test('with find', () => {
const counter1 = createCounter();
const counter2 = createCounter();
const result = pipe(
[10, 20, 30, 40] as const,
counter1.fn(),
flatMap(x => [x, x + 1, x + 2, x + 3]),
counter2.fn(),
find(x => x === 22)
);
expect(counter1.count).toHaveBeenCalledTimes(2);
expect(counter2.count).toHaveBeenCalledTimes(7);
expect(result).toEqual(22);
});
});
});