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

Module Call Tracker

Build a testing utility that automatically mocks an external module and tracks all method invocations for verification in tests.

Requirements

Your implementation should:

  1. Automatically mock a specified module using Jest's module mocking system
  2. Track all method calls with their arguments
  3. Provide access to call history and call counts for each mocked method
  4. Allow resetting the tracking state between tests

Test Cases

Module Mocking

  • When a module is mocked using jest.mock(), all its exported functions should be automatically mocked @test

Call Tracking

  • After calling a mocked method, it should be possible to verify it was called with specific arguments @test
  • Multiple calls to the same method should be tracked with the correct total count @test

Metadata Retrieval

  • The tracker should provide access to call history including all arguments for each invocation @test
  • The tracker should return the total number of times each mocked method was called @test

Implementation

@generates

API

/**
 * Creates a call tracker that mocks the specified module
 *
 * @param {string} modulePath - Path to the module to mock
 * @returns {object} Tracker interface
 */
function createTracker(modulePath) {
  // Returns an object with:
  // - getMock(): returns the mocked module
  // - getCallsFor(methodName): returns array of call arguments arrays
  // - getCallCount(methodName): returns number of times method was called
  // - reset(): clears all mock call history
}

module.exports = { createTracker };

Dependencies { .dependencies }

jest { .dependency }

Provides testing framework with module mocking capabilities including automatic module mocking, mock function creation, and call tracking.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-jest-each

tile.json