Parameterised tests for Jest that enable running the same test multiple times with different data sets using arrays or tagged template literals
85
Create a test suite that manages database connections using lifecycle hooks. The suite should set up a database connection once before all tests, clean up data between tests, and close the connection after all tests complete.
Implement a test suite with the following behavior:
The test suite should verify that:
@generates
/**
* Mock database object with connection lifecycle methods
*/
const database = {
/**
* Establishes a connection to the database
* @returns {Promise<void>}
*/
connect: async function() {},
/**
* Disconnects from the database
* @returns {Promise<void>}
*/
disconnect: async function() {},
/**
* Clears all test data from the database
* @returns {Promise<void>}
*/
clearData: async function() {},
/**
* Checks if database is currently connected
* @returns {boolean}
*/
isConnected: function() {},
/**
* Inserts test data
* @param {any} data - Data to insert
* @returns {Promise<void>}
*/
insert: async function(data) {}
};
/**
* Mock logger for tracking test execution
*/
const logger = {
/**
* Logs a message
* @param {string} message - Message to log
*/
log: function(message) {}
};Provides the testing framework and lifecycle hooks.
@satisfied-by
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