Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Resetting Mock For Specific Function Parameters #108

Closed
mrrosoff opened this issue Nov 22, 2024 · 1 comment
Closed

Support Resetting Mock For Specific Function Parameters #108

mrrosoff opened this issue Nov 22, 2024 · 1 comment

Comments

@mrrosoff
Copy link

mrrosoff commented Nov 22, 2024

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");
@timkindberg
Copy link
Owner

v3.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants