From b709d318dd37bf7ca06ac6db6acb55e8834a2a85 Mon Sep 17 00:00:00 2001 From: Svyatoslav Zaytsev Date: Wed, 15 Jan 2025 12:11:44 +0500 Subject: [PATCH] feat: add onGenerateMock transformer callback (#15429) --- docs/JestObjectAPI.md | 4 ++-- packages/jest-environment/src/index.ts | 12 ------------ 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index 7634ed7776ab..66a292876da2 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -530,10 +530,10 @@ Returns a mock module instead of the actual module, bypassing all checks on whet ### `jest.onGenerateMock(cb)` -Registers a callback function that is invoked whenever Jest generates a mock for a module. -This callback allows you to modify the mock before it is returned to the rest of your tests. +Registers a callback function that is invoked whenever Jest generates a mock for a module. This callback allows you to modify the mock before it is returned to the rest of your tests. Parameters for callback: + 1. `moduleName: string` - The name of the module that is being mocked. 2. `moduleMock: T` - The mock object that Jest has generated for the module. This object can be modified or replaced before returning. diff --git a/packages/jest-environment/src/index.ts b/packages/jest-environment/src/index.ts index 892c99bd25f2..04a02ae10c0c 100644 --- a/packages/jest-environment/src/index.ts +++ b/packages/jest-environment/src/index.ts @@ -207,18 +207,6 @@ export interface Jest { moduleFactory?: () => T, options?: {virtual?: boolean}, ): Jest; - /** - * Registers a callback function that is invoked whenever a mock is generated for a module. - * This callback is passed the module name and the newly created mock object, and must return - * the (potentially modified) mock object. - * - * If multiple callbacks are registered, they will be called in the order they were added. - * Each callback receives the result of the previous callback as the `moduleMock` parameter, - * making it possible to apply sequential transformations. - * - * @param cb - */ - onGenerateMock(cb: (moduleName: string, moduleMock: T) => T): Jest; /** * Mocks a module with the provided module factory when it is being imported. */