Ctrl + K
DocumentationLog inGet started

tessl/npm-jest-circus

tessl install tessl/npm-jest-circus@29.7.0

The next-gen flux-based test runner for Jest that provides test framework globals and event-driven test execution

Agent Success

Agent success rate when using this tile

82%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.91x

Baseline

Agent success rate without this tile

43%

task.mdevals/scenario-8/

Async Data Fetcher Testing

Build a test suite for an asynchronous data fetcher utility that validates promise-based operations.

Background

You're testing a data fetching utility that makes asynchronous requests to retrieve user data. The utility returns promises that either resolve with data or reject with errors based on various conditions.

Requirements

Create tests for a DataFetcher class with the following methods:

  1. fetchUser(id) - Returns a promise that resolves with user data when given a valid user ID (positive integer), or rejects with an error for invalid IDs (negative or zero).

  2. fetchMultipleUsers(ids) - Returns a promise that resolves with an array of user objects when all IDs are valid, or rejects if any ID is invalid.

  3. fetchUserWithTimeout(id, timeout) - Returns a promise that resolves with user data if the fetch completes within the timeout, or rejects with a timeout error otherwise.

Write tests that verify:

  • Successful promise resolutions return the expected data structure
  • Promise rejections occur for invalid inputs with appropriate error messages
  • Multiple successful async operations complete correctly
  • Timeout scenarios are handled properly

Test Cases

Your test suite must include the following test cases:

  • Fetching a valid user ID resolves with an object containing id and name properties @test
  • Fetching an invalid user ID (zero or negative) rejects with an error message "Invalid user ID" @test
  • Fetching multiple valid user IDs resolves with an array of user objects @test
  • Fetching multiple users with one invalid ID rejects with an error @test
  • Fetching with sufficient timeout resolves successfully @test
  • Fetching with insufficient timeout rejects with "Timeout exceeded" error @test

Implementation

@generates

API

class DataFetcher {
  /**
   * Fetches user data for a given user ID.
   * @param {number} id - User ID (must be positive)
   * @returns {Promise<{id: number, name: string}>} Promise resolving to user object
   */
  fetchUser(id) {
    // Implementation simulates async fetch
  }

  /**
   * Fetches multiple users by their IDs.
   * @param {number[]} ids - Array of user IDs
   * @returns {Promise<Array<{id: number, name: string}>>} Promise resolving to array of users
   */
  fetchMultipleUsers(ids) {
    // Implementation simulates async fetch for multiple users
  }

  /**
   * Fetches user with a timeout constraint.
   * @param {number} id - User ID
   * @param {number} timeout - Timeout in milliseconds
   * @returns {Promise<{id: number, name: string}>} Promise resolving to user object
   */
  fetchUserWithTimeout(id, timeout) {
    // Implementation simulates async fetch with timeout
  }
}

module.exports = { DataFetcher };

Dependencies { .dependencies }

jest { .dependency }

Provides testing framework and assertion capabilities.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/jest-circus@29.7.x
tile.json