forked from remeda/remeda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forEachObj.test.ts
48 lines (43 loc) · 1.05 KB
/
forEachObj.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
36
37
38
39
40
41
42
43
44
45
46
47
48
import { forEachObj } from './forEachObj';
import { pipe } from './pipe';
const obj = {
a: 1,
b: 2,
c: 3,
};
describe('data_first', () => {
it('forEachObj', () => {
const cb = vi.fn();
const result = forEachObj(obj, cb);
expect(cb.mock.calls).toEqual([[1], [2], [3]]);
expect(result).toEqual(obj);
});
it('forEachObj.indexed', () => {
const cb = vi.fn();
const result = forEachObj.indexed(obj, cb);
expect(cb.mock.calls).toEqual([
[1, 'a', obj],
[2, 'b', obj],
[3, 'c', obj],
]);
expect(result).toEqual(obj);
});
});
describe('data_last', () => {
it('forEachObj', () => {
const cb = vi.fn();
const result = pipe(obj, forEachObj(cb));
expect(cb.mock.calls).toEqual([[1], [2], [3]]);
expect(result).toEqual(obj);
});
it('forEachObj.indexed', () => {
const cb = vi.fn();
const result = pipe(obj, forEachObj.indexed(cb));
expect(cb.mock.calls).toEqual([
[1, 'a', obj],
[2, 'b', obj],
[3, 'c', obj],
]);
expect(result).toEqual(obj);
});
});