marchaos / jest-mock-extended

Type safe mocking extensions for Jest https://www.npmjs.com/package/jest-mock-extended
MIT License
810 stars 56 forks source link

allow overriding calledWithFn #96

Closed dlech closed 1 year ago

dlech commented 2 years ago

By using unshift instead of push, new callbacks are added to the "top" of the stack (since find searches from the beginning of the array). This allow a second call to calledWith() to override a previous call. This is useful for one-off tests.

Fixes #77.

fellnerse commented 1 year ago

Awesome, this would be really helpful for us! Do you know when this will be merged?

marchaos commented 1 year ago

Hey. Would you be able to add a test that verifies this? Thanks.

dlech commented 1 year ago

Test has been added. I confirmed that it fails before the change and succeeds after the change.

marchaos commented 1 year ago

I'll merge this into 3.0.0 when that is released (trying to release that asap), since there's a small chance of breaking existing tests.