fix(unbound-method): ignore inline use of jest.mocked(...)#1862
fix(unbound-method): ignore inline use of jest.mocked(...)#1862G-Rath merged 8 commits intojest-community:mainfrom
jest.mocked(...)#1862Conversation
G-Rath
left a comment
There was a problem hiding this comment.
at this point I feel like this is an overly complicated solution - have you looked into why our existing logic for handling jest.mocked isn't catching this case?
Sorry for the response, in this case the |
G-Rath
left a comment
There was a problem hiding this comment.
I still would expect we can identify the call with parseJestFn, but what you've got it a lot simpler than what you had before and finding the right node to parse can be a pain at times, so I'm happy to go with this once you've simplified it a bit more with the isSupportedAccessor change
src/rules/unbound-method.ts
Outdated
| // Check if the call is jest.mocked() by examining the callee | ||
| if ( | ||
| parentCall.callee.type === AST_NODE_TYPES.MemberExpression && | ||
| isSupportedAccessor(parentCall.callee.object) && |
There was a problem hiding this comment.
isSupportedAccessor takes an optional value as its second param for just these situations - so rather than having to do the work twice, you can just do isSupportedAccessor(..., 'jest')
that in turn means you should be able to refactor this all to be a return
src/rules/unbound-method.ts
Outdated
|
|
||
| // Also try using parseJestFnCall as a fallback | ||
| // const jestFnCall = parseJestFnCall( | ||
| // findTopMostCallExpression(parentCall), | ||
| // context, | ||
| // ); | ||
|
|
||
| // return ( | ||
| // jestFnCall?.type === 'jest' && | ||
| // jestFnCall.members.length >= 1 && | ||
| // isIdentifier(jestFnCall.members[0], 'mocked') | ||
| // ); |
There was a problem hiding this comment.
| // Also try using parseJestFnCall as a fallback | |
| // const jestFnCall = parseJestFnCall( | |
| // findTopMostCallExpression(parentCall), | |
| // context, | |
| // ); | |
| // return ( | |
| // jestFnCall?.type === 'jest' && | |
| // jestFnCall.members.length >= 1 && | |
| // isIdentifier(jestFnCall.members[0], 'mocked') | |
| // ); |
| node: TSESTree.MemberExpression, | ||
| ): boolean => { | ||
| // Check if the immediate parent is a CallExpression | ||
| if (node.parent?.type !== AST_NODE_TYPES.CallExpression) { |
There was a problem hiding this comment.
this is the opposite of the check we do later on, so ideally we can merge the two but that might be messy due to the optional chaining and require an else which I try to avoid so not too fussed to keep it like this for now
There was a problem hiding this comment.
I agreed. I tried another way, but it still failed.
|
As mentioned before, the |
jest.mocked(...)
## [29.11.1](v29.11.0...v29.11.1) (2025-12-29) ### Bug Fixes * **unbound-method:** ignore inline use of `jest.mocked(...)` ([#1862](#1862)) ([3a50b97](3a50b97))
|
🎉 This PR is included in version 29.11.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Fix: #1800