Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions src/checkPassword.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,60 @@
'use strict';

describe(`Function 'checkPassword':`, () => {
const checkPassword = require('./checkPassword');
const checkPassword = require('./checkPassword');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import line is fine — require('./checkPassword') is correct and necessary for these tests. No change required here.


describe(`Function 'checkPassword':`, () => {
it(`should be declared`, () => {
expect(checkPassword).toBeInstanceOf(Function);
});

it(`should return boolean`, () => {
it(`should return a boolean`, () => {
const result = checkPassword('Password1!');
expect(typeof result).toBe('boolean');
});
Comment on lines +10 to +13

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test only asserts the return type for 'Password1!'. The task description explicitly lists checkPassword('Password1!') === true as a required example. Add a dedicated test asserting expect(checkPassword('Password1!')).toBe(true) so the example from the specification is covered exactly .


it(`should return true for valid password with 8 characters`, () => {
const result = checkPassword('Abcdef1!');
expect(result).toBe(true);
});

it(`should return true for valid password with 16 characters`, () => {
const result = checkPassword('Abcdefgh1234!XYZ');
expect(result).toBe(true);
});

it(`should return false for password shorter than 8 characters`, () => {
const result = checkPassword('Ab1!');
expect(result).toBe(false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The short-password test uses 'Ab1!' (length 4). The spec requires an explicit check for a 7-character password (should be false). Add a test using exactly 7 characters so the inclusive lower boundary (8) is precisely verified (e.g., a 7-character string that otherwise contains required character classes where possible).

});

it(`should return false for password longer than 16 characters`, () => {
const result = checkPassword('Abcdefghijklmnop1!');
expect(result).toBe(false);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The long-password test uses 'Abcdefghijklmnop1!', which is 18 characters. The spec requires an explicit check for a 17-character password (should be false) and that exactly 16 characters is accepted. You already test a 16-char valid case, but please include a 17-character invalid test specifically to validate the inclusive upper bound of 16.


it(`should return false for password without uppercase letter`, () => {
const result = checkPassword('abcdef1!');
expect(result).toBe(false);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You test absence of uppercase (good). Complement this with a positive test that a password composed of only uppercase letters (plus at least one digit and one special char and valid length) is accepted — the spec does not require a lowercase letter. Example: expect(checkPassword('ABCDEF12!')).toBe(true) — add this to ensure uppercase-only but otherwise valid passwords pass.


it(`should return false for password without digit`, () => {
const result = checkPassword('Abcdefgh!');
expect(result).toBe(false);
});

it(`should return 'true' for the valid password with 8 characters`, () => {
it(`should return false for password without special character`, () => {
const result = checkPassword('Abcdefg1');
expect(result).toBe(false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suite does not clarify whether whitespace is allowed. The spec implies special characters are allowed but whitespace is usually not intended. Add a test containing a space (e.g., 'Abcdef1 !' or 'Abc def1!') and assert the intended behavior (likely false). This makes the policy explicit and avoids ambiguity.

});

it(`should return false for password with non-Latin characters`, () => {
const result = checkPassword('Пароль1!');
expect(result).toBe(false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You correctly test a Cyrillic password which should be rejected. Also add a test with accented Latin letters (e.g., 'Pässword1!' or 'Passwörd1!') to ensure accented characters are rejected if the implementation must accept only ASCII Latin letters (A–Z, a–z). This expands non-Latin coverage beyond Cyrillic as required by the spec.

});

// write more tests here
it(`should return true for password with mix of allowed symbols`, () => {
const result = checkPassword('XyZ123@#');
expect(result).toBe(true);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add explicit tests for the other two example strings from the description: checkPassword('qwerty') === false and checkPassword('Str@ng') === false. These examples are required by the spec and should be present as individual tests alongside the existing ones .

});