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

Test Suite Validator

A utility that validates user input forms and runs comprehensive tests with descriptive error messages.

Capabilities

Form data validation

Validates that form submissions contain required fields and proper data types.

  • When given an object with username (string) and age (number), returns { valid: true } @test
  • When given an object missing the username field, returns { valid: false, error: "Missing required field: username" } @test
  • When given an object where age is not a number, returns { valid: false, error: "Invalid type for field: age" } @test

Async data fetching validation

Validates data retrieved from asynchronous operations.

  • When fetching user data that resolves successfully, the returned object contains a userId property @test
  • When fetching user data that rejects, the error message contains "User not found" @test

Implementation

@generates

API

/**
 * 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,
};

Dependencies { .dependencies }

jest-expect-message { .dependency }

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-message

tile.json