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-2/

Test Suite with Database Connection Management

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.

Requirements

Implement a test suite with the following behavior:

  1. Connection Setup: Establish a database connection once before running any tests in the suite
  2. Data Reset: Clear all test data from the database before each individual test runs
  3. Connection Cleanup: Close the database connection once after all tests have completed
  4. State Tracking: After each test completes, log the test name that just finished

The test suite should verify that:

  • The connection is established before tests run
  • Data is properly reset before each test
  • Multiple tests can run in sequence with proper cleanup between them
  • The connection is closed after all tests finish

Implementation

@generates

API

/**
 * 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) {}
};

Test Cases

  • Database is connected when first test runs @test
  • Data is cleared before the second test @test
  • Logger records test completion @test
  • Database is disconnected after all tests @test

Dependencies { .dependencies }

jest { .dependency }

Provides the testing framework and lifecycle hooks.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-jest-each

tile.json