Skip to content

Keep original function implementation when not matched#82

Merged
timkindberg merged 1 commit intotimkindberg:masterfrom
materkel:master
Sep 19, 2021
Merged

Keep original function implementation when not matched#82
timkindberg merged 1 commit intotimkindberg:masterfrom
materkel:master

Conversation

@materkel
Copy link
Copy Markdown

@materkel materkel commented Aug 25, 2021

resolves #78

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

@timkindberg
Copy link
Copy Markdown
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
Copy Markdown
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