Passed
Pull Request — master (#140)
by Pieter Epeüs
03:26 queued 11s
created

src/__tests__/map-objects.spec.js   A

Complexity

Total Complexity 5
Complexity/F 1

Size

Lines of Code 49
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 33
mnd 0
bc 0
fnc 5
dl 0
loc 49
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
1
import { expect, describe, it } from '@jest/globals';
2
import Obj from '../objects';
3
4
const testSchema = {
5
    a: Number,
6
    b: Number,
7
};
8
9
const Test = Obj({ schema: testSchema });
10
11
describe('Test objects.js map', () => {
12
    it('It should map the object like the array map', () => {
13
        const input = {
14
            a: 1,
15
            b: 2,
16
        };
17
        const expectedResult = {
18
            a: 2,
19
            b: 4,
20
        };
21
22
        expect(Test.create(input).map((x) => x * 2)).toMatchObject(
23
            expectedResult
24
        );
25
    });
26
27
    it('It should map the flat object like the array map', () => {
28
        const input = {
29
            a: 1,
30
            b: 2,
31
            c: [3, 4],
32
            d: { e: 5, f: 6 },
33
            g: { h: { i: 7 } },
34
        };
35
        const expectedResult = {
36
            a: 2,
37
            b: 4,
38
            'c.0': 6,
39
            'c.1': 8,
40
            'd.e': 10,
41
            'd.f': 12,
42
            'g.h.i': 14,
43
        };
44
45
        expect(Test.create(input).flatMap((x) => x * 2)).toMatchObject(
46
            expectedResult
47
        );
48
    });
49
});
50