Add custom message to Jest expects
Overall
score
99%
Build a user data validation module that validates user profile data with descriptive test error messages.
Create a validation module that checks user profile objects for correctness. The module should validate:
All validation functions should throw descriptive errors when validation fails.
Write comprehensive tests with custom error messages. Configure error output differently based on the test scenario:
@generates
/**
* Validates username meets requirements.
* @param {string} username - Username to validate
* @throws {Error} If username is invalid
*/
function validateUsername(username) {
// Implementation
}
/**
* Validates email address format.
* @param {string} email - Email to validate
* @throws {Error} If email format is invalid
*/
function validateEmail(email) {
// Implementation
}
/**
* Validates age is within acceptable range.
* @param {number} age - Age to validate
* @throws {Error} If age is out of range
*/
function validateAge(age) {
// Implementation
}
/**
* Validates complete user profile.
* @param {Object} profile - User profile object
* @throws {Error} If profile is incomplete or invalid
*/
function validateProfile(profile) {
// Implementation
}
module.exports = { validateUsername, validateEmail, validateAge, validateProfile };Provides custom message support for Jest assertions with configurable error output formatting.
@satisfied-by
Install 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