Skip to content

Commit b709d31

Browse files
committed
feat: add onGenerateMock transformer callback (#15429)
1 parent f3888ef commit b709d31

File tree

2 files changed

+2
-14
lines changed

2 files changed

+2
-14
lines changed

docs/JestObjectAPI.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -530,10 +530,10 @@ Returns a mock module instead of the actual module, bypassing all checks on whet
530530

531531
### `jest.onGenerateMock(cb)`
532532

533-
Registers a callback function that is invoked whenever Jest generates a mock for a module.
534-
This callback allows you to modify the mock before it is returned to the rest of your tests.
533+
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.
535534

536535
Parameters for callback:
536+
537537
1. `moduleName: string` - The name of the module that is being mocked.
538538
2. `moduleMock: T` - The mock object that Jest has generated for the module. This object can be modified or replaced before returning.
539539

packages/jest-environment/src/index.ts

-12
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,6 @@ export interface Jest {
207207
moduleFactory?: () => T,
208208
options?: {virtual?: boolean},
209209
): Jest;
210-
/**
211-
* Registers a callback function that is invoked whenever a mock is generated for a module.
212-
* This callback is passed the module name and the newly created mock object, and must return
213-
* the (potentially modified) mock object.
214-
*
215-
* If multiple callbacks are registered, they will be called in the order they were added.
216-
* Each callback receives the result of the previous callback as the `moduleMock` parameter,
217-
* making it possible to apply sequential transformations.
218-
*
219-
* @param cb
220-
*/
221-
onGenerateMock<T>(cb: (moduleName: string, moduleMock: T) => T): Jest;
222210
/**
223211
* Mocks a module with the provided module factory when it is being imported.
224212
*/

0 commit comments

Comments
 (0)