-
-
Notifications
You must be signed in to change notification settings - Fork 245
London | 25-ITP-Sep | Payman Issa Baiglu | sprint 3 | 3-strech #885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
London | 25-ITP-Sep | Payman Issa Baiglu | sprint 3 | 3-strech #885
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is working. I just have a few suggestions.
| const isLongEnough = password.length >= 5; | ||
| const hasUpper = /[A-Z]/.test(password); | ||
| const hasLower = /[a-z]/.test(password); | ||
| const hasNumber = /[0-9]/.test(password); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can consider name it hasDigit. '0', ..., '9' are called digits.
| test("password has at least 5 characters", () => { | ||
| // Arrange | ||
| const password = "12345"; | ||
| // Act | ||
| const password = "12345Aa!"; | ||
| const result = isValidPassword(password); | ||
| // Assert | ||
| expect(result).toEqual(true); | ||
| } | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could also consider testing boundary cases:
- Valid password with 5 characters
- A 4-character password containing all required characters.
| test("password missing uppercase letter", () => { | ||
| const password = "12345aa!"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| } | ||
| ); | ||
| test("password missing lowercase letter", () => { | ||
| const password = "12345AA!"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| } | ||
| ); | ||
| test("password missing number", () => { | ||
| const password = "Abcde!"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| } | ||
| ); | ||
| test("password missing special character", () => { | ||
| const password = "12345Aa"; | ||
| const result = isValidPassword(password); | ||
| expect(result).toEqual(false); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to also specify in the test description
- the expected behavior of the function ("should return false when ..."), or
- indicate the test is for invalid passwords
Password vaidator which is checking all the conditions required. I wrote it in 2 versins. 1st one is commented so the tests can pass.