Add custom message to Jest expects
Overall
score
99%
Build a test utility that validates user input and reports failures with custom error messages. The utility should provide flexible control over how error information is displayed when validation fails.
Create a validation function that checks if user input meets specific criteria. When validation fails, the error output should be configurable to show different levels of detail based on the testing context.
Implement a validateUserInput(input) function that:
username, email, and agetrue if all validations pass, false otherwiseValidation rules:
username: must be a non-empty string with at least 3 charactersemail: must contain an "@" symbolage: must be a number greater than or equal to 18Write tests in validator.test.js that verify the validation function with different error reporting configurations:
Each test should use custom error messages to describe what is being validated
Provides custom error messages for test assertions.
Input:
{
username: "john_doe",
email: "john@example.com",
age: 25
}Expected behavior: Validation returns true
Input:
{
username: "ab",
email: "test@example.com",
age: 20
}Expected behavior: Validation returns false
Input:
{
username: "testuser",
email: "invalidemail",
age: 30
}Expected behavior: Validation returns false
validator.js - Implementation of the validation functionvalidator.test.js - Test suite demonstrating different error reporting configurationsInstall with Tessl CLI
npx tessl i tessl/npm-jest-expect-messagedocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10