This repository has been archived by the owner on May 8, 2021. It is now read-only.
generated from mellonis-edu/assignment-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.test.js
68 lines (55 loc) · 1.68 KB
/
library.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
63
64
65
66
67
68
import specialCharacters from './specialCharacters';
import {
getRandomAlpha,
getRandomDigit,
getRandomSpecialChar,
} from './library';
describe('library.js', () => {
describe('getRandomAlpha', () => {
test('getRandomAlpha is a function', () => {
expect(getRandomAlpha).toBeInstanceOf(Function);
});
test('getRandomAlpha returns a letter', () => {
const regExp = /^[a-z]$/i;
expect(
[...new Array(52)]
.every(() => {
const result = getRandomAlpha();
return typeof result === 'string' && result.length === 1 && regExp.test(result);
}),
)
.toBe(true);
});
});
describe('getRandomDigit', () => {
test('getRandomDigit is a function', () => {
expect(getRandomDigit).toBeInstanceOf(Function);
});
test('getRandomDigit returns a digit', () => {
const regExp = /^[0-9]$/;
expect(
[...new Array(20)]
.every(() => {
const result = getRandomDigit();
return typeof result === 'string' && result.length === 1 && regExp.test(result);
}),
)
.toBe(true);
});
});
describe('getRandomSpecialChar', () => {
test('getRandomSpecialChar is a function', () => {
expect(getRandomSpecialChar).toBeInstanceOf(Function);
});
test('getRandomSpecialChar returns a special char', () => {
expect(
[...new Array(specialCharacters.length * 2)]
.every(() => {
const result = getRandomSpecialChar();
return typeof result === 'string' && result.length === 1 && specialCharacters.includes(result);
}),
)
.toBe(true);
});
});
});