Skip to content

[Feature]: support type inference for function parameters expect(someFunction).toBeCalledWith() #13267

@royhadad

Description

@royhadad

🚀 Feature Proposal

When using the following code:

expect(someFunction).toBeCalledWith()

The type expected as arguments for toBeCalledWith is any[]
This can be overridden by passing a type argument:

expect(someFunction).toBeCalledWith<Parameters<someFunction>>()

My proposal is to have it inferred automatically by default.
https://www.typescriptlang.org/docs/handbook/utility-types.html#parameterstype

Similar methods should also be updated (e.g. toHaveBeenCalledWith, lastCalledWith)

Motivation

When using toBeCalledWith, users will get instant feedback and auto-completion for the arguments passed.

Example

No response

Pitch

It will improve the DX of using jest.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions