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-5/

Custom Test Error Reporter

Overview { .overview }

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.

Goal { .goal }

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.

Requirements { .requirements }

  1. Implement a validateUserInput(input) function that:

    • Takes an object with properties: username, email, and age
    • Returns true if all validations pass, false otherwise
  2. Validation rules:

    • username: must be a non-empty string with at least 3 characters
    • email: must contain an "@" symbol
    • age: must be a number greater than or equal to 18
  3. Write tests in validator.test.js that verify the validation function with different error reporting configurations:

    • Test case with minimal output (hide prefix and stack trace)
    • Test case with custom message only (hide matcher message and stack)
    • Test case with full detailed output (all information visible)
  4. Each test should use custom error messages to describe what is being validated

Dependencies { .dependencies }

jest-expect-message { .dependency }

Provides custom error messages for test assertions.

Test Cases { .test-cases }

Test Case 1: Valid user input { .test-case data-auto-run=true }

Input:

{
  username: "john_doe",
  email: "john@example.com",
  age: 25
}

Expected behavior: Validation returns true

Test Case 2: Invalid username { .test-case data-auto-run=true }

Input:

{
  username: "ab",
  email: "test@example.com",
  age: 20
}

Expected behavior: Validation returns false

Test Case 3: Missing email symbol { .test-case data-auto-run=true }

Input:

{
  username: "testuser",
  email: "invalidemail",
  age: 30
}

Expected behavior: Validation returns false

Deliverables { .deliverables }

  1. validator.js - Implementation of the validation function
  2. validator.test.js - Test suite demonstrating different error reporting configurations

Install with Tessl CLI

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

tile.json