Skip to content

Support Resetting Mock For Specific Function Parameters #108

@mrrosoff

Description

@mrrosoff

I have a mock, and I have setup a call.

const mock = jest.fn();
when(mock).calledWith("hello").mockResolvedValue("world");

I then need to implement "Once" style calls, overriding the function.

mock.mockReset();
when(mock).calledWith("hello").mockResolvedValueOnce("world");
when(mock).calledWith("hello").mockResolvedValueOnce("example");

Unfortunately, this clears all existing when mocks. Ideally, I could do this, which would clear any mocks for this specific set of arguments.

when(mock).calledWith("hello").mockReset()

It could then be chained something like this:

when(mock).calledWith("hello").mockResolvedValue("world");
when(mock)
    .calledWith("hello")
    .mockReset()
    .mockResolvedValueOnce("example");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions