Skip to content

Commit

Permalink
feat(unbound-method): ignore functions passed to jest.mocked (#1681)
Browse files Browse the repository at this point in the history
* feat(unbound-methods): ignore functions passed to `jest.mocked`

* refactor(unbound-methods): use `parseJestFnCall`
  • Loading branch information
FloEdelmann authored Dec 19, 2024
1 parent c223c1a commit d868636
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/rules/__tests__/unbound-method.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const validTestCases: string[] = [
'expect(Console.prototype.log).toHaveBeenCalledTimes(1);',
'expect(Console.prototype.log).not.toHaveBeenCalled();',
'expect(Console.prototype.log).toStrictEqual(somethingElse);',
'jest.mocked(Console.prototype.log).mockImplementation(() => {});',
].map(code => [ConsoleClassAndVariableCode, code].join('\n')),
dedent`
expect(() => {
Expand Down
9 changes: 9 additions & 0 deletions src/rules/unbound-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
createRule,
findTopMostCallExpression,
getAccessorValue,
isIdentifier,
parseJestFnCall,
} from './utils';

Expand Down Expand Up @@ -84,6 +85,14 @@ export default createRule<Options, MessageIds>({
context,
);

if (
jestFnCall?.type === 'jest' &&
jestFnCall.members.length >= 1 &&
isIdentifier(jestFnCall.members[0], 'mocked')
) {
return;
}

if (jestFnCall?.type === 'expect') {
const { matcher } = jestFnCall;

Expand Down

0 comments on commit d868636

Please # to comment.