-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
utils.spec.ts
63 lines (57 loc) · 2.24 KB
/
utils.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* global it, expect, describe */
import { trimWS, XMLEscape } from "../src/utils";
import { defaultConfig } from "../src/config";
describe("Whitespace trim", () => {
describe("#trimLeft", () => {
it("WS slurp with str.trimLeft", () => {
expect(trimWS(" jestjs", defaultConfig, "_")).toBe("jestjs");
});
it("WS slurp without str.trimLeft", () => {
Object.defineProperty(String.prototype, "trimLeft", { value: undefined });
expect(trimWS(" jestjs", defaultConfig, "_")).toBe("jestjs");
});
it("WS newline", () => {
expect(trimWS("\njestjs", defaultConfig, "-")).toBe("jestjs");
});
it("WS slurp and WS newline are equal with newline", () => {
Object.defineProperty(String.prototype, "trimLeft", { value: undefined });
expect(trimWS(" jestjs", defaultConfig, "_")).toBe(trimWS("\njestjs", defaultConfig, "-"));
});
});
describe("#trimRight", () => {
it("WS slurp with str.trimRight", () => {
expect(trimWS("jestjs ", defaultConfig, "", "_")).toBe("jestjs");
});
it("WS slurp without str.trimRight", () => {
Object.defineProperty(String.prototype, "trimRight", { value: undefined });
expect(trimWS("jestjs ", defaultConfig, "", "_")).toBe("jestjs");
});
it("WS newline", () => {
expect(trimWS("jestjs\n", defaultConfig, "", "-")).toBe("jestjs");
});
it("WS slurp and WS newline are equal with newline", () => {
Object.defineProperty(String.prototype, "trimRight", { value: undefined });
expect(trimWS("jestjs ", defaultConfig, "", "_")).toBe(
trimWS("jestjs\n", defaultConfig, "", "-")
);
});
});
describe("#trim", () => {
it("WS slurp both sides", () => {
expect(
trimWS(" somestring ", { ...defaultConfig, autoTrim: ["slurp", "slurp"] }, "", "")
).toBe("somestring");
});
it("defaultConfig.autoTrim set to false", () => {
expect(trimWS(" some string\n ", { ...defaultConfig, autoTrim: false }, "", "")).toBe(
" some string\n "
);
});
});
});
describe("HTML Escape", () => {
it("properly escapes HTML characters", () => {
expect(XMLEscape("<p>HTML</p>")).toBe("<p>HTML</p>");
expect(XMLEscape("no html here")).toBe("no html here");
});
});