feat(jest-mock): add mockFn.mock.lastCall to retrieve last argument#12285
feat(jest-mock): add mockFn.mock.lastCall to retrieve last argument#12285SimenB merged 7 commits intojestjs:mainfrom Biki-das:doc-mock
mockFn.mock.lastCall to retrieve last argument#12285Conversation
Codecov Report
@@ Coverage Diff @@
## main #12285 +/- ##
=======================================
Coverage 67.52% 67.52%
=======================================
Files 328 328
Lines 17244 17246 +2
Branches 5069 5070 +1
=======================================
+ Hits 11644 11646 +2
Misses 5567 5567
Partials 33 33
Continue to review full report at Codecov.
|
|
hey @SimenB does this sound useful to you? |
SimenB
left a comment
There was a problem hiding this comment.
I like it, thanks! Left some nits 🙂
| mockFn.mock.instances[1] === b; // true | ||
| ``` | ||
|
|
||
| ### `mockFn.mock.lastCall` |
There was a problem hiding this comment.
it should not be added to all versioned docs, only the ones in docs/
| calls: [], | ||
| instances: [], | ||
| invocationCallOrder: [], | ||
| lastCall: undefined, |
There was a problem hiding this comment.
it should just not be here I think, not set to undefined (which might be a return value)
| this._mockState.set(f, state); | ||
| } | ||
|
|
||
| state.lastCall = state.calls[state.calls.length - 1]; |
There was a problem hiding this comment.
check if state.calls.length > 0 first
|
thanks @SimenB , will surely update this with the required changes |
Co-authored-by: Simen Bekkhus <[email protected]>
Co-authored-by: Simen Bekkhus <[email protected]>
|
Hm.. Jest has If there is a need users can add more custom matchers, hence keeping the I think the proposal in this PR is overlapping with current functionality (the Just wanted to leave a note. Might be I miss some use case. |
|
My main motivation is that it'd make |
yes that is the intention that i also had while introducing this one |
You know it better (; As I said, might be I miss some use cases. |
|
hey @SimenB is there any problem with my PR'S i am not getting any feedback , or am i doing something wrong? |
mockFn.mock.lastCall to retrieve last argument
I understand , sorry for my pings, take care. |
|
No worries! |
|
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. |
Summary
When switching from using sinon mocks to jest, one of the nice things that sinon provided was the ability to retrieve the last call arguments easily. I know that you can use mockFn.mock.calls[mockFn.mock.calls.length - 1] to retrieve it, but mock.lastCall seems a lot easier when you're doing it in a bunch of places. I wanted to at least try adding it and see what the response was. I understand if this is not needed, but it seems like a nice little improvement.
Test plan
I've updated types, added tests for the feature and updated documentation. I ran yarn test for the entire test suite to verify that it was working.