Add custom message to Jest expects
Overall
score
99%
A utility that validates user input forms and runs comprehensive tests with descriptive error messages.
Validates that form submissions contain required fields and proper data types.
username (string) and age (number), returns { valid: true } @testusername field, returns { valid: false, error: "Missing required field: username" } @testage is not a number, returns { valid: false, error: "Invalid type for field: age" } @testValidates data retrieved from asynchronous operations.
userId property @test@generates
/**
* Validates form data for required fields and types.
*
* @param {Object} formData - The form data to validate
* @returns {Object} Validation result with { valid: boolean, error?: string }
*/
function validateForm(formData) {
// IMPLEMENTATION HERE
}
/**
* Fetches user data asynchronously and returns a promise.
*
* @param {number} userId - The user ID to fetch
* @returns {Promise<Object>} Promise that resolves with user data or rejects with error
*/
function fetchUserData(userId) {
// IMPLEMENTATION HERE
}
module.exports = {
validateForm,
fetchUserData,
};Provides enhanced Jest assertions with custom error messages for better test debugging and readability.
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