-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathcheckPassword.test.js
More file actions
75 lines (58 loc) · 2.22 KB
/
checkPassword.test.js
File metadata and controls
75 lines (58 loc) · 2.22 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
'use strict';
const checkPassword = require('./checkPassword');
describe(`Function 'checkPassword':`, () => {
it(`should be declared`, () => {
expect(checkPassword).toBeInstanceOf(Function);
});
it(`should return a boolean`, () => {
const result = checkPassword('Password1!');
expect(typeof result).toBe('boolean');
});
// README examples
it(`should return true for checkPassword('Password1!')`, () => {
expect(checkPassword('Password1!')).toBe(true);
});
it(`should return false for checkPassword('qwerty')`, () => {
expect(checkPassword('qwerty')).toBe(false);
});
it(`should return false for checkPassword('Str@ng')`, () => {
expect(checkPassword('Str@ng')).toBe(false);
});
// Length boundaries
it(`should return false for 7-character password`, () => {
expect(checkPassword('Abcde1!')).toBe(false);
});
it(`should return true for 8-character valid password`, () => {
expect(checkPassword('Abcdef1!')).toBe(true);
});
it(`should return true for 16-character valid password`, () => {
expect(checkPassword('Abcdefgh1234!XYZ')).toBe(true);
});
it(`should return false for 17-character password`, () => {
// 15 liter + 1 cyfra + 1 znak specjalny = 17 znaków
expect(checkPassword('Abcdefghijklmno1!')).toBe(false);
});
// Character class coverage
it(`should return false for password without uppercase`, () => {
expect(checkPassword('abcdef1!')).toBe(false);
});
it(`should return false for password without digit`, () => {
expect(checkPassword('Abcdefgh!')).toBe(false);
});
it(`should return false for password without special char`, () => {
expect(checkPassword('Abcdefg1')).toBe(false);
});
it(`should return true for uppercase-only valid password`, () => {
expect(checkPassword('ABCDEF12!')).toBe(true);
});
it(`should return false for password with Cyrillic letters`, () => {
expect(checkPassword('Пароль1!')).toBe(false);
});
it(`should return false for password with accented Latin letters`, () => {
expect(checkPassword('Pässword1!')).toBe(false);
});
// Whitespace check
it(`should return false for password containing whitespace`, () => {
expect(checkPassword('Abc def1!')).toBe(false);
});
});