Use TDD For A Password Rule
Apply Red-Green-Refactor to add a password validation rule with one small behavior at a time.
Reject passwords that contain the user's email local-part, such as email nora@example.com and password Nora2026!. Red: failing example. Green: smallest passing code. Refactor: clearer design under green tests. The common trap is to add the condition directly into a long validator without first proving the old behavior failed or cleaning up after green. Red Write validatePassword_containsEmailLocalPart_returnsInvalid with email nora@example.com and password Nora2026!; assert valid is false and reason includes contains_email. The test should fail because the validator does not yet know this rule. Red validates the test. Green Pass email into the validator and add the smallest case-insensitive local-part check…
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in