-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSanitizer.test.ts
63 lines (47 loc) · 1.73 KB
/
Sanitizer.test.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
import { expect, test } from '@jest/globals';
import { DateSanitizer, GenderSanitizer, StringSanitizer } from './Sanitizer';
/*******************/
/* StringSanitizer */
/*******************/
test('StringSanitizer', () => {
let ss = new StringSanitizer();
expect(ss.sanitize("hello")).toBe("hello");
// To lower case
expect(ss.sanitize("HELLO")).toBe("hello");
expect(ss.sanitize("HelloWorld")).toBe("helloworld");
// Remove spaces from both ends
expect(ss.sanitize(" hello")).toBe("hello");
expect(ss.sanitize(" hello")).toBe("hello");
expect(ss.sanitize("hello ")).toBe("hello");
expect(ss.sanitize("hello ")).toBe("hello");
expect(ss.sanitize(" hello ")).toBe("hello");
// Convert multiple spaces to single space
expect(ss.sanitize("hello world")).toBe("hello world");
expect(ss.sanitize("hello world")).toBe("hello world");
expect(ss.sanitize("hello\tworld")).toBe("hello world");
expect(ss.sanitize("hello \t \t world")).toBe("hello world");
});
/*******************/
/* GenderSanitizer */
/*******************/
test('GenderSanitizer', () => {
let gs = new GenderSanitizer();
const maleWords = ["male", "MALE", "Male", "MalE", "man", "boy", "M", "m"];
maleWords.forEach(word => {
expect(gs.sanitize(word)).toBe("M");
});
const femaleWords = ["female", "FEMALE", "Female", "FemalE", "woman", "girl", "F", "f"];
femaleWords.forEach(word => {
expect(gs.sanitize(word)).toBe("F");
});
expect(() => gs.sanitize("")).toThrow();
expect(() => gs.sanitize("unknown")).toThrow();
});
/*****************/
/* DateSanitizer */
/*****************/
test('DateSanitizer', () => {
let ds = new DateSanitizer();
let date = new Date("2020-01-01");
expect(ds.sanitize(date)).toEqual(date);
});