-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathcheckPassword.test.js
More file actions
86 lines (65 loc) · 2.89 KB
/
checkPassword.test.js
File metadata and controls
86 lines (65 loc) · 2.89 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
/* eslint-disable max-len */
'use strict';
describe(`Function 'checkPassword':`, () => {
const checkPassword = require('./checkPassword');
it(`should be declared`, () => {
expect(checkPassword).toBeInstanceOf(Function);
});
it(`should return boolean`, () => {
expect(typeof checkPassword('12345678')).toEqual('boolean');
});
it(`should return true for valid password with exactly 8 characters`, () => {
expect(checkPassword('P@ssw0r1')).toEqual(true);
});
it(`should return true for valid password with 9 characters`, () => {
expect(checkPassword('P@ssw0rd!')).toEqual(true);
});
it(`should return false when the password is less than 8 characters`, () => {
expect(checkPassword('P@sw0rd')).toEqual(false);
});
it(`should return true for valid password with exactly 16 characters`, () => {
expect(checkPassword('P@ssw0rd!P@ssw0r')).toEqual(true);
});
it(`should return false when the password is more than 16 characters`, () => {
expect(checkPassword('P@ssw0rd!P@ssw0rd!')).toEqual(false);
});
it(`should return false when password has no uppercase letter`, () => {
expect(checkPassword('p@ssw0rd!')).toEqual(false);
});
it(`should return false when password has no lowercase letter (function requires both upper and lower)`, () => {
expect(checkPassword('P@SSW0RD!')).toEqual(false);
});
it(`should return false when password has no digit`, () => {
expect(checkPassword('Password!')).toEqual(false);
});
it(`should return false when password has no special character`, () => {
expect(checkPassword('Passw0rd')).toEqual(false);
});
it(`should return false when password contains spaces`, () => {
expect(checkPassword('P@s sw0rd!')).toEqual(false);
});
it(`should return true for example password 'Password1!'`, () => {
expect(checkPassword('Password1!')).toEqual(true);
});
it(`should return false for example password 'qwerty'`, () => {
expect(checkPassword('qwerty')).toEqual(false);
});
it(`should return false for example password 'Str@ng'`, () => {
expect(checkPassword('Str@ng')).toEqual(false);
});
it(`should return true when password contains non-Latin letters like ä (function does not block them)`, () => {
expect(checkPassword('Pässw0rd!')).toEqual(true);
});
it(`should return false when password contains Cyrillic letters (Рassword1!)`, () => {
expect(checkPassword('Рassword1!')).toEqual(false);
});
it(`should return true for minimal valid password with all required categories (A1!aaaaa)`, () => {
expect(checkPassword('A1!aaaaa')).toEqual(true);
});
it(`should return true for password with multiple specials and digits (P@ssw0rd!!11)`, () => {
expect(checkPassword('P@ssw0rd!!11')).toEqual(true);
});
it(`should return false when password has uppercase + special but no digit (Passw@rd)`, () => {
expect(checkPassword('Passw@rd')).toEqual(false);
});
});