Skip to content

Conversation

@PaymanIB
Copy link

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Password vaidator which is checking all the conditions required. I wrote it in 2 versins. 1st one is commented so the tests can pass.

@PaymanIB PaymanIB added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 16, 2025
Copy link
Contributor

@cjyuan cjyuan left a 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);
Copy link
Contributor

@cjyuan cjyuan Nov 21, 2025

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.

Comment on lines 18 to -26
test("password has at least 5 characters", () => {
// Arrange
const password = "12345";
// Act
const password = "12345Aa!";
const result = isValidPassword(password);
// Assert
expect(result).toEqual(true);
}
);
Copy link
Contributor

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.

Comment on lines +24 to +46
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);
}
Copy link
Contributor

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

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants