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

Keep original function implementation when not matched #82

Merged
merged 1 commit into from
Sep 19, 2021

Conversation

materkel
Copy link

@materkel materkel commented Aug 25, 2021

resolves #78

imo this is also more in line with the jest default behavior

@timkindberg
Copy link
Owner

timkindberg commented Aug 28, 2021

Thank you very much for this contribution!

Do you know will this also work with a mock that has an existing mockReturnValue as well?

See #59

@materkel
Copy link
Author

Just checked the test setup @narthur provided in #59 with my solution, unfortunately this does not work, the original jest setup still has to be defined before calling when on it in this case.

const fn = jest.fn()

when(fn).calledWith(1).mockReturnValue('a')

fn.mockReturnValue('b')

expect(fn(1)).toEqual('a') // fails and will still return 'b' (as before my change)
expect(fn(2)).toEqual('b')

Not sure if #59 is solved quite as easily (from my limited understanding of the code)

@timkindberg timkindberg merged commit fe6dba9 into timkindberg:master Sep 19, 2021
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

Successfully merging this pull request may close these issues.

Keep default implementation when attaching to an existing mock
2 participants