Skip to content

Commit

Permalink
feat: add onGenerateMock transformer callback (jestjs#15429)
Browse files Browse the repository at this point in the history
  • Loading branch information
MillerSvt committed Jan 15, 2025
1 parent f3888ef commit b709d31
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/JestObjectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
12 changes: 0 additions & 12 deletions packages/jest-environment/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(cb: (moduleName: string, moduleMock: T) => T): Jest;
/**
* Mocks a module with the provided module factory when it is being imported.
*/
Expand Down

0 comments on commit b709d31

Please sign in to comment.