CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-jest-each

Parameterised tests for Jest that enable running the same test multiple times with different data sets using arrays or tagged template literals

85

1.10x
Overview
Eval results
Files

task.mdevals/scenario-5/

API Timeout Testing Suite

Build a test suite that validates timeout behavior for an external API client. The test suite should handle both fast and slow API operations with appropriate timeout configurations.

Requirements

Create a test file that tests the following scenarios for an API client that makes HTTP requests:

  1. Fast operations - Operations that complete quickly (under 1 second) should pass with default timeout
  2. Slow operations - Operations that take longer (2-5 seconds) should be given extended timeouts to avoid false failures
  3. Very slow operations - Operations that intentionally take a very long time (10+ seconds) should have appropriately configured timeouts
  4. Timeout failures - Operations that exceed their configured timeout should fail appropriately

The API client to test is provided below. Your test suite should properly configure timeouts for different test scenarios.

API Client

The following API client is provided for testing:

// src/api-client.js
class ApiClient {
  async fetchQuick() {
    await new Promise(resolve => setTimeout(resolve, 100));
    return { data: 'quick response' };
  }

  async fetchSlow() {
    await new Promise(resolve => setTimeout(resolve, 3000));
    return { data: 'slow response' };
  }

  async fetchVerySlow() {
    await new Promise(resolve => setTimeout(resolve, 12000));
    return { data: 'very slow response' };
  }

  async fetchWithError() {
    await new Promise(resolve => setTimeout(resolve, 6000));
    throw new Error('API Error');
  }
}

module.exports = ApiClient;

Test Cases

Your test suite should include:

  • Quick API call passes with default timeout @test
  • Slow API call passes with extended timeout @test
  • Very slow API call passes with sufficient timeout @test
  • API call that exceeds timeout limit fails appropriately @test

Implementation

@generates

Expected Behavior

  • Quick operations should pass with standard timeout settings
  • Slow operations should pass when given adequate timeout
  • Very slow operations should pass when given sufficient timeout
  • Tests should be able to demonstrate timeout failure for operations that exceed limits

Dependencies { .dependencies }

jest { .dependency }

Provides testing framework and timeout configuration capabilities.

Install with Tessl CLI

npx tessl i tessl/npm-jest-each

tile.json