Skip to content

Commit d868636

Browse files
authored
feat(unbound-method): ignore functions passed to jest.mocked (#1681)
* feat(unbound-methods): ignore functions passed to `jest.mocked` * refactor(unbound-methods): use `parseJestFnCall`
1 parent c223c1a commit d868636

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/rules/__tests__/unbound-method.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const validTestCases: string[] = [
6161
'expect(Console.prototype.log).toHaveBeenCalledTimes(1);',
6262
'expect(Console.prototype.log).not.toHaveBeenCalled();',
6363
'expect(Console.prototype.log).toStrictEqual(somethingElse);',
64+
'jest.mocked(Console.prototype.log).mockImplementation(() => {});',
6465
].map(code => [ConsoleClassAndVariableCode, code].join('\n')),
6566
dedent`
6667
expect(() => {

src/rules/unbound-method.ts

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
createRule,
88
findTopMostCallExpression,
99
getAccessorValue,
10+
isIdentifier,
1011
parseJestFnCall,
1112
} from './utils';
1213

@@ -84,6 +85,14 @@ export default createRule<Options, MessageIds>({
8485
context,
8586
);
8687

88+
if (
89+
jestFnCall?.type === 'jest' &&
90+
jestFnCall.members.length >= 1 &&
91+
isIdentifier(jestFnCall.members[0], 'mocked')
92+
) {
93+
return;
94+
}
95+
8796
if (jestFnCall?.type === 'expect') {
8897
const { matcher } = jestFnCall;
8998

0 commit comments

Comments
 (0)