UNPKG

test-pwd-strength

Version:

[![npm version](https://img.shields.io/npm/v/password-strength-checker.svg)](https://www.npmjs.com/package/password-strength-checker) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

26 lines (22 loc) 875 B
const { checkStrength } = require('./index'); test('checks password strength correctly', () => { // Test weak password (too short) const weak = checkStrength('abc'); expect(weak.strength).toBe('weak'); // Test strong password (meets all requirements) const strong = checkStrength('Passw0rd!'); expect(strong.strength).toBe('strong'); // Test medium password (only meets length requirement) const medium = checkStrength('longpassword', { requireNumbers: false, requireUppercase: false, requireSymbols: false, }); expect(medium.strength).toBe('weak'); // Now correct (score = 30) // Test with some requirements enabled const custom = checkStrength('Password', { requireNumbers: false, requireSymbols: false, }); expect(custom.strength).toBe('medium'); // Score = 30 (length) + 20 (uppercase) = 50 });