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 payment processing system that handles payments through different providers. The system should support testing various payment scenarios using mock implementations.
Implement a payment processor with the following functionality:
processPayment that accepts an amount and provider name, then calls the appropriate provider functioncreditCardProvider, paypalProvider, and cryptoProviderWrite tests that verify:
@generates
/**
* Processes a payment using the specified provider
* @param {number} amount - The payment amount
* @param {string} provider - The payment provider name
* @returns {Promise<{status: string, transactionId: string}>} Payment result
*/
async function processPayment(amount, provider) {
// Implementation
}
/**
* Credit card payment provider
* @param {number} amount - The payment amount
* @returns {Promise<{status: string, transactionId: string}>} Payment result
*/
async function creditCardProvider(amount) {
// Implementation
}
/**
* PayPal payment provider
* @param {number} amount - The payment amount
* @returns {Promise<{status: string, transactionId: string}>} Payment result
*/
async function paypalProvider(amount) {
// Implementation
}
/**
* Crypto payment provider
* @param {number} amount - The payment amount
* @returns {Promise<{status: string, transactionId: string}>} Payment result
*/
async function cryptoProvider(amount) {
// Implementation
}
module.exports = {
processPayment,
creditCardProvider,
paypalProvider,
cryptoProvider
};Provides testing framework and mocking 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