Passed
Push — es2015 ( 64e5b0...a07c6e )
by Luís
01:47
created

index.test.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 1
rs 10
c 4
b 0
f 0
1
jest.autoMockOff();
0 ignored issues
show
Bug introduced by
The variable jest seems to be never declared. If this is a global, consider adding a /** global: jest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2
3
import ObjectHelper from "../index";
4
5
const equals = (actual, expected) => expect(actual).toBe(expected);
6
7
const testObject = {
8
    a: {
9
        a: {
10
            b: 1,
11
            c: 2,
12
            d: null
13
        },
14
        b: 1
15
    }
16
};
17
18
test("Test getFlattened", () => {
19
    equals(ObjectHelper.getFlattened("a.b", testObject, "x"), 1);
20
    equals(ObjectHelper.getFlattened("a.a.b", testObject, "x"), 1);
21
    equals(ObjectHelper.getFlattened("a.a.c", testObject, "x"), 2);
22
    equals(ObjectHelper.getFlattened("a.a.f", testObject, "x"), "x");
23
});
24
25
test("Test setFlattened", () => {
26
    let localTestObject = Object.assign({}, testObject);
27
    let response = ObjectHelper.setFlattened("a.b", 2, localTestObject);
28
    equals(response.a.b, 2);
29
30
    localTestObject = Object.assign({}, testObject);
31
    equals(response.a.c, undefined);
32
    response = ObjectHelper.setFlattened("a.c", 2, localTestObject);
33
    equals(response.a.c, 2);
34
});
35
36
test("Test firstKey", () => {
37
    equals(ObjectHelper.firstKey(testObject), "a");
38
    equals(ObjectHelper.firstKey(testObject.a.a), "b");
39
});