Passed
Pull Request — master (#2)
by Luís
03:48 queued 02:00
created

index.test.js ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 1
c 5
b 0
f 0
nc 1
dl 0
loc 1
rs 10
nop 2
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 ArrayHelper from "../index";
4
5
const equals = (actual, expected) => expect(actual).toBe(expected);
6
const testCollection = [{a: 100}, {a: 1}, {a: 5}];
7
8
test("Test sortByObjectKey ASC", () => {
9
    const expected = [{a: 1}, {a: 5}, {a: 100}];
10
    const result = ArrayHelper.sortByObjectKey(testCollection, "a", "asc");    
11
    expected.map((expected, index) => equals(result[index].a, expected.a));
12
    expect(result.length, expected.length);
13
});
14
15
test("Test sortByObjectKey DESC", () => {
16
    const expected = [{a: 100}, {a: 5}, {a: 1}];
17
    const result = ArrayHelper.sortByObjectKey(testCollection, "a", "desc");
18
    
19
    expected.map((expected, index) => equals(result[index].a, expected.a));
20
    expect(result.length, expected.length);
21
});
22
23
test("Test sortByObjectKey should be default ASC", () => {
24
    const expected = [{a: 1}, {a: 5}, {a: 100}];
25
    const result = ArrayHelper.sortByObjectKey(testCollection, "a");
26
    
27
    expected.map((expected, index) => equals(result[index].a, expected.a));
28
    expect(result.length, expected.length);
29
});
30
31
test("Test filter by", () => {
32
    const expected = [{a: 5}, {a: 100}];
33
    const result = ArrayHelper.filterBy("a", [5, 100], testCollection);
34
    expected.map((expected, index) => equals(result[index].a, expected.a));
35
    expect(result.length, expected.length);
36
});