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

User Validator Test Suite

Write a comprehensive test suite for a user validation module with descriptive error messages.

Background

You are testing a user validation module that validates user objects. Your tests should include clear, descriptive error messages that explain what is being validated, making it easier to understand test failures.

Requirements

Validation Rules

The user validation module validates user objects with the following rules:

  • Users must have a username field (string)
  • Users must have an age field (number, must be 18 or above)
  • Users may optionally have an email field (string, must contain '@')

Test Implementation

Write a test suite that validates these rules. Each test should include a descriptive custom message that will be displayed if the assertion fails.

You'll need to implement a simple validateUser function that checks these rules, and then write tests for it.

@generates

Test Cases

Your test suite should include the following scenarios:

  • It validates a user with valid username and age @test
  • It rejects a user without a username @test
  • It rejects a user with age below 18 @test
  • It validates email format when provided @test
  • It handles async validation for checking username availability @test

Each test should include a descriptive custom message that explains what is being validated.

Example Output

When a test fails, the output should clearly show your custom message along with the assertion details. For example:

Custom message:
  User age must be at least 18

expect(received).toBeGreaterThanOrEqual(expected)
Expected: >= 18
Received: 16

Dependencies { .dependencies }

jest-expect-message { .dependency }

Provides enhanced test assertions with custom error messages.

jest { .dependency }

JavaScript testing framework.

Install with Tessl CLI

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

tile.json