/
index.test.js
62 lines (50 loc) · 1.44 KB
/
index.test.js
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
const generateUniqueId = require('./index');
describe('ID', () => {
it('should be generated without passing any additional arguments', () => {
const id1 = generateUniqueId();
const id2 = generateUniqueId();
expect(id1.length).toBe(20);
expect(id1).not.toMatch(id2);
});
it('should contain only letters', () => {
const id = generateUniqueId({
useNumbers: false,
length: 50,
});
expect(id.match(/[0-9]/g)).toBe(null);
expect(id.length).toBe(50);
});
it('should contain only numbers', () => {
const id = generateUniqueId({
useLetters: false,
length: 30,
});
expect(id.match(/[a-z]/g)).toBe(null);
expect(id.length).toBe(30);
});
it('should include certain symbols', () => {
const id = generateUniqueId({
includeSymbols: ['@', '#'],
length: 100,
});
expect(((/(@|#)/g)).test(id)).toBe(true);
expect(id.length).toBe(100);
const id2 = generateUniqueId({
includeSymbols: ['@', '#'],
length: 10,
useLetters: false,
useNumbers: false,
});
expect(id2.match(/[a-z0-9]/g)).toBe(null);
expect(id2.includes('@')).toBe(true);
expect(id2.includes('#')).toBe(true);
expect(id2.length).toBe(10);
});
it('should exclude certain symbols', () => {
const id = generateUniqueId({
useLetters: false,
excludeSymbols: ['0', '1', '2', '3', '4', '5'],
});
expect(id.match(/[0-5]/g)).toBe(null);
});
});