Skip to content

Commit b0dc2e4

Browse files
authored
refactor(jest-mock)!: simplify usage of jest.fn generic type arguments (#12489)
1 parent b6df016 commit b0dc2e4

9 files changed

Lines changed: 528 additions & 377 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323
- `[@jest/expect-utils]` New module exporting utils for `expect` ([#12323](https://github.com/facebook/jest/pull/12323))
2424
- `[jest-haste-map]` [**BREAKING**] `HasteMap.create` now returns a promise ([#12008](https://github.com/facebook/jest/pull/12008))
2525
- `[jest-haste-map]` Add support for `dependencyExtractor` written in ESM ([#12008](https://github.com/facebook/jest/pull/12008))
26-
- `[jest-mock]` [**BREAKING**] Rename exported utility types `ConstructorLike`, `MethodLike`, `ConstructorLikeKeys`, `MethodLikeKeys`, `PropertyLikeKeys`; remove exports of utility types `ArgumentsOf`, `ArgsType`, `ConstructorArgumentsOf` - TS builtin utility types `ConstructorParameters` and `Parameters` should be used instead ([#12435](https://github.com/facebook/jest/pull/12435))
26+
- `[jest-mock]` [**BREAKING**] Rename exported utility types `ClassLike`, `FunctionLike`, `ConstructorLikeKeys`, `MethodLikeKeys`, `PropertyLikeKeys`; remove exports of utility types `ArgumentsOf`, `ArgsType`, `ConstructorArgumentsOf` - TS builtin utility types `ConstructorParameters` and `Parameters` should be used instead ([#12435](https://github.com/facebook/jest/pull/12435), [#12489](https://github.com/facebook/jest/pull/12489))
2727
- `[jest-mock]` Improve `isMockFunction` to infer types of passed function ([#12442](https://github.com/facebook/jest/pull/12442))
28+
- `[jest-mock]` [**BREAKING**] Improve the usage of `jest.fn` generic type argument ([#12489](https://github.com/facebook/jest/pull/12489))
2829
- `[jest-mock]` Add support for auto-mocking async generator functions ([#11080](https://github.com/facebook/jest/pull/11080))
2930
- `[jest-resolve]` [**BREAKING**] Add support for `package.json` `exports` ([#11961](https://github.com/facebook/jest/pull/11961), [#12373](https://github.com/facebook/jest/pull/12373))
3031
- `[jest-resolve, jest-runtime]` Add support for `data:` URI import and mock ([#12392](https://github.com/facebook/jest/pull/12392))

docs/JestObjectAPI.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ const otherCopyOfMyModule = require('myModule');
453453

454454
## Mock Functions
455455

456-
### `jest.fn(implementation)`
456+
### `jest.fn(implementation?)`
457457

458458
Returns a new, unused [mock function](MockFunctionAPI.md). Optionally takes a mock implementation.
459459

@@ -467,6 +467,12 @@ const returnsTrue = jest.fn(() => true);
467467
console.log(returnsTrue()); // true;
468468
```
469469

470+
:::note
471+
472+
See [Mock Functions](MockFunctionAPI.md#jestfnimplementation) page for details on TypeScript usage.
473+
474+
:::
475+
470476
### `jest.isMockFunction(fn)`
471477

472478
Determines if the given function is a mocked function.

0 commit comments

Comments
 (0)