Passed
Pull Request — master (#2)
by Luís
03:41 queued 01:55
created

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

Complexity

Total Complexity 10
Complexity/F 1

Size

Lines of Code 66
Function Count 10

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 10
c 1
b 0
f 0
nc 1
mnd 0
bc 9
fnc 10
dl 0
loc 66
rs 10
bpm 0.9
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 StringHelper from "../index";
4
5
const equals = (actual, expected) => expect(actual).toBe(expected);
6
7
test("Test resolveUrl", () => {
8
    const basepath = "http://x.com/";
9
10
    const hash = {
11
        "http://google.com": "http://google.com",
12
        "https://google.com": "https://google.com",
13
        "//google.com": "//google.com"
14
    };
15
16
    Object.keys(hash).map((url) => {
17
        equals(StringHelper.resolveUrl(url), hash[url]);
18
    });
19
20
    equals(StringHelper.resolveUrl("http://google.com", basepath), "http://google.com");
21
    equals(StringHelper.resolveUrl("foo/bar", basepath), `${basepath}foo/bar`);
22
});
23
24
test("Test ucfirst", () => {
25
    const hash = {
26
        "oba": "Oba",
27
        "oba oba": "Oba oba",
28
        "": "",
29
        "1": "1"
30
    };
31
32
    Object.keys(hash).map((word) => {
33
        equals(StringHelper.ucfirst(word), hash[word]);
34
        equals(StringHelper.capitalize(word), hash[word]);
35
    });
36
});
37
38
test("Test ucwords", () => {
39
    const hash = {
40
        "oba": "Oba",
41
        "oba oba": "Oba Oba",
42
        "": "",
43
        "1": "1"
44
    };
45
46
    Object.keys(hash).map((word) => {
47
        equals(StringHelper.ucwords(word), hash[word]);
48
    });
49
});
50
51
test("Test excerpt", () => {
52
    const hash = {
53
        "This is a phrase": {
54
            3: "This...",
55
            4: "This...",
56
            5: "This...",
57
            7: "This is a..."
58
        },
59
    };
60
61
    Object.keys(hash).map(phrase => {
62
        Object.keys(hash[phrase]).map(maxLength => {
63
            equals(StringHelper.excerpt(phrase, maxLength), hash[phrase][maxLength]);
64
        });
65
    });
66
});