Add custom message to Jest expects
Overall
score
99%
Create a test suite for a user validation module that uses descriptive error messages to make test failures easier to understand.
You are testing a user validation module that checks various properties of user objects. When tests fail, you want clear, descriptive error messages that explain exactly what validation failed, making debugging faster and easier.
Create a test suite that:
{
username: string, // must be alphanumeric, 3-20 characters
email: string, // must be valid email format
age: number, // must be >= 18
active: boolean
}Your test suite should validate:
Write test cases that clearly communicate what each assertion validates. When a test fails, the error message should immediately indicate which validation rule was violated.
@generates
Your tests should follow this general pattern:
// Test structure with enhanced error messages
describe('User Validation', () => {
test('validates user age requirement', () => {
const user = { username: 'john', email: 'john@example.com', age: 25, active: true };
// Add assertions here with descriptive error messages
// Use syntax that provides context when validation fails
});
test('validates username format', () => {
const user = { username: 'validuser', email: 'user@example.com', age: 20, active: true };
// Add assertions with context about username requirements
});
// Additional test cases...
});Provides custom error message support for Jest assertions.
@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