Skip to content

Commit a787c53

Browse files
authored
docs: Document getMockImplementation() (#15766)
1 parent 38daf70 commit a787c53

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/MockFunctionAPI.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,32 @@ import TOCInline from '@theme/TOCInline';
1919

2020
## Reference
2121

22+
### `mockFn.getMockImplementation()`
23+
24+
Returns the current implementation of the mock function set by [`mockImplementation()`](#mockfnmockimplementationfn). Returns `undefined` if no implementation has been set.
25+
26+
```js tab
27+
const mockFn = jest.fn();
28+
29+
mockFn.getMockImplementation(); // undefined
30+
31+
mockFn.mockImplementation(() => 42);
32+
33+
mockFn.getMockImplementation(); // () => 42
34+
```
35+
36+
```ts tab
37+
import {jest} from '@jest/globals';
38+
39+
const mockFn = jest.fn<() => number>();
40+
41+
mockFn.getMockImplementation(); // undefined
42+
43+
mockFn.mockImplementation(() => 42);
44+
45+
mockFn.getMockImplementation(); // () => 42
46+
```
47+
2248
### `mockFn.getMockName()`
2349

2450
Returns the mock name string set by calling [`.mockName()`](#mockfnmocknamename).

0 commit comments

Comments
 (0)