src/__tests__/every-object.spec.js   A
last analyzed

Complexity

Total Complexity 9
Complexity/F 1

Size

Lines of Code 56
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 35
mnd 0
bc 0
fnc 9
dl 0
loc 56
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.js';
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 every', () => {
13
    it('It should return true because every value is below 4', () => {
14
        const input = {
15
            a: 1,
16
            b: 2,
17
            c: 3,
18
        };
19
20
        expect(Test.create(input).every((x) => x < 4)).toBeTruthy();
21
    });
22
23
    it('It should return false because not every value is below 3', () => {
24
        const input = {
25
            a: 1,
26
            b: 2,
27
            c: 3,
28
        };
29
30
        expect(Test.create(input).every((x) => x < 3)).toBeFalsy();
31
    });
32
33
    it('It should return true because every flat value is below 3', () => {
34
        const input = {
35
            a: 1,
36
            b: 2,
37
            c: [1, 2],
38
            d: { e: 1, f: 2 },
39
            g: { h: { i: 1 } },
40
        };
41
42
        expect(Test.create(input).flatEvery((x) => x < 3)).toBeTruthy();
43
    });
44
45
    it('It should return false because not every flat value is 2', () => {
46
        const input = {
47
            a: 1,
48
            b: 2,
49
            c: [1, 2],
50
            d: { e: 1, f: 2 },
51
            g: { h: { i: 1 } },
52
        };
53
54
        expect(Test.create(input).flatEvery((x) => x === 2)).toBeFalsy();
55
    });
56
});
57