CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jest-expect-message

Add custom message to Jest expects

Overall
score

99%

Overview
Eval results
Files

task.mdevals/scenario-6/

User Validation Test Suite

Create a test suite for a user validation module that uses descriptive error messages to make test failures easier to understand.

Background

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.

Requirements

Create a test suite that:

  1. Tests user validation logic: Write tests for validating user objects (age, email format, username requirements, etc.)
  2. Provides clear failure context: Each assertion should include a descriptive message explaining what is being validated
  3. Uses various assertion types: Include equality checks, property checks, negations, and pattern matching
  4. Maintains clean syntax: Keep test code readable and maintainable

Expected User Object Structure

{
  username: string,  // must be alphanumeric, 3-20 characters
  email: string,     // must be valid email format
  age: number,       // must be >= 18
  active: boolean
}

Test Scenarios

Your test suite should validate:

  • User age is at least 18 with a descriptive error message @test
  • Username meets length requirements, with error context explaining the rule @test
  • Email format is valid, with a message identifying which validation failed @test
  • Inactive users are properly identified using negation with context @test

Implementation

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

API

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...
});

Dependencies { .dependencies }

jest-expect-message { .dependency }

Provides custom error message support for Jest assertions.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-jest-expect-message

tile.json