1
|
|
|
jest.autoMockOff(); |
|
|
|
|
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
|
|
|
}); |
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.