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

src/js/helpers/array/__tests__/index.test.js   A

Complexity

Total Complexity 9
Complexity/F 1

Size

Lines of Code 36
Function Count 9

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 9
c 1
b 0
f 0
nc 1
mnd 0
bc 4
fnc 9
dl 0
loc 36
rs 10
bpm 0.4444
cpm 1
noi 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A index.test.js ➔ ??? 0 1 1
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
});