Parameterised tests for Jest that enable running the same test multiple times with different data sets using arrays or tagged template literals
85
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.
Create a test file that tests the following scenarios for an API client that makes HTTP requests:
The API client to test is provided below. Your test suite should properly configure timeouts for different test scenarios.
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;Your test suite should include:
@generates
Provides testing framework and timeout configuration capabilities.
Install with Tessl CLI
npx tessl i tessl/npm-jest-eachdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10