-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.test.js
More file actions
103 lines (71 loc) · 2.24 KB
/
index.test.js
File metadata and controls
103 lines (71 loc) · 2.24 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
const msk = require("./index");
const uglify = require("uglify-js");
const fs = require("fs");
test("should mask numbers", () => {
const value = "123";
const mask = "9 9 9";
const result = msk(value, mask);
expect(result).toBe("1 2 3");
});
test("should mask alpha characters", () => {
const value = "abc";
const mask = "A A A";
const result = msk(value, mask);
expect(result).toBe("a b c");
});
test("should mask alphaanumeric characters", () => {
const value = "abc123";
const mask = "S S SS SS";
const result = msk(value, mask);
expect(result).toBe("a b c1 23");
});
test("should mask any characters", () => {
const value = "-.1a";
const mask = "* * * *";
const result = msk(value, mask);
expect(result).toBe("- . 1 a");
});
test("should return empty string if input is empty", () => {
const value = "-.1a";
const mask = "* * * *";
const resultFirstArgument = msk("", mask);
const resultSecondArgument = msk(value, "");
expect(resultFirstArgument).toBe("");
expect(resultSecondArgument).toBe("");
});
test("should remove exceeding characters", () => {
const value = "22250-040ops";
const mask = "99999-999";
const result = msk.fit(value, mask);
expect(result).toBe("22250-040");
});
test("should pass uglify", () => {
const minify = () => uglify.minify("index.js");
expect(minify).not.toThrow();
});
describe("README examples", () => {
it("should mask the phone example properly", () => {
const value = "552122222222";
const mask = "+99 (99) 9999-9999";
const result = msk(value, mask);
expect(result).toBe("+55 (21) 2222-2222");
});
it("should mask the Canadian postal code example properly", () => {
const value = "V6G1C9";
const mask = "A9A 9A9";
const result = msk(value, mask);
expect(result).toBe("V6G 1C9");
});
it("should mask the anything symbol example properly", () => {
const value = "I love msk";
const mask = "*-****-***";
const result = msk(value, mask);
expect(result).toBe("I-love-msk");
});
it("should mask removing exceeding characters example properly", () => {
const value = "22231-0004131";
const mask = "99999-999";
const result = msk.fit(value, mask);
expect(result).toBe("22231-000");
});
});