Skip to content

Conversation

@feliperli
Copy link
Contributor

Summary

The motivation described at this issue is to instead of returning undefined for mockReset return the original function itself.

Test plan

const myObject = {bar: () => 'bar'}; let barStub: any; beforeAll(() => { barStub = jest.spyOn(myObject, 'bar'); }); test('run #1', () => { barStub.mockReturnValue('POTATO!'); expect(myObject.bar()).toBe('POTATO!'); barStub.mockReset(); // This expect should be successful expect(myObject.bar()).toBe('bar'); });
@cpojer
Copy link
Member

cpojer commented Jan 3, 2023

Can you add e2e tests that verify that this behavior is working and add a line to the CHANGELOG.md?

@SimenB
Copy link
Member

SimenB commented Jan 3, 2023

Should probably update the docs as well to specify what we're skipping?

@feliperli
Copy link
Contributor Author

@cpojer @SimenB e2e test added and changelog updated. not sure if we should update the docs, tho, since this is a bug and didn't changed the general idea of mockReset and resetAllMocks

@mrazauskas
Copy link
Contributor

not sure if we should update the docs, tho, since this is a bug and didn't changed the general idea of mockReset and resetAllMocks

The linked issue is pointing to a note from this line of documentaion:

https://github.com/facebook/jest/blob/a325f8790d99029e45d215fcfc27790aa2bda131/docs/MockFunctionAPI.md?plain=1#L129

I guess the text in parenthesis should be deleted, or?

@feliperli
Copy link
Contributor Author

Thanks @mrazauskas

@SimenB
Copy link
Member

SimenB commented Jan 4, 2023

@feliperli there's a type error

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@SimenB SimenB changed the title [Feature]: stop changing the behaviour of spies on mockFn.mockReset fix: stop changing the behaviour of spies on mockFn.mockReset Jan 6, 2023
@SimenB SimenB merged commit eace3a1 into jestjs:main Jan 6, 2023
@github-actions
Copy link

github-actions bot commented Feb 6, 2023

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

5 participants