Skip to content

4.0.0

Choose a tag to compare

@timkindberg timkindberg released this 23 Mar 23:44
· 7 commits to master since this release

Highlights

  • jest-when is now authored in TypeScript
  • fixes a number of long-standing typing issues, especially around wrapper mocks, calledWith inference, and void / Promise<void> cases
  • compatibility is now verified in both Jest 29 and Jest 27 environments

What changed

Native TypeScript source

The library source has been migrated from JavaScript to TypeScript, with the public type contract now tested directly in the repo.

Stronger, more accurate typings

This release tightens a number of important typing behaviors:

  • calledWith / expectCalledWith preserve argument tuple types again
  • mockReturnValue / mockResolvedValue / related methods track the mocked function's return type much more accurately
  • void / Promise<void> cases allow omitted values correctly
  • better support for function-like wrapper mocks, including jest-mock-extended-style mocked object methods
  • typed casts, mocked module functions, spies, optional args, rest args, allArgs, and matcher cases are now covered by contract tests

Compatibility guardrails

The repo now has:

  • a primary Jest 29 development environment
  • a dedicated compat/jest27 workspace

The full build, runtime tests, and type tests run in both environments. This was added specifically to avoid fixing newer Jest/mock ecosystems while regressing older supported ones.

Breaking changes

  • minimum supported Jest version is now 27
  • TypeScript usages that previously compiled because the old typings were too loose may now fail typechecking

There are no intentional runtime API changes in this release.

Thanks

Thanks to @tlevesque-ueat for the repros, patience, and repeated validation while this got sorted out.