Passed
Push — master ( 228692...8b570f )
by Pieter Epeüs
01:55 queued 11s
created

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

Complexity

Total Complexity 5
Complexity/F 1

Size

Lines of Code 50
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 50
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
//  deepcode ignore ExpectsArray: False error, it should allow an object
10
const Test = Obj({ schema: testSchema });
11
12
describe('Test objects.js map', () => {
13
    it('It should map the object like the array map', () => {
14
        const input = {
15
            a: 1,
16
            b: 2,
17
        };
18
        const expectedResult = {
19
            a: 2,
20
            b: 4,
21
        };
22
23
        expect(Test.create(input).map((x) => x * 2)).toMatchObject(
24
            expectedResult
25
        );
26
    });
27
28
    it('It should map the flat object like the array map', () => {
29
        const input = {
30
            a: 1,
31
            b: 2,
32
            c: [3, 4],
33
            d: { e: 5, f: 6 },
34
            g: { h: { i: 7 } },
35
        };
36
        const expectedResult = {
37
            a: 2,
38
            b: 4,
39
            'c.0': 6,
40
            'c.1': 8,
41
            'd.e': 10,
42
            'd.f': 12,
43
            'g.h.i': 14,
44
        };
45
46
        expect(Test.create(input).flatMap((x) => x * 2)).toMatchObject(
47
            expectedResult
48
        );
49
    });
50
});
51