diff --git a/src/rules/__tests__/unbound-method.test.ts b/src/rules/__tests__/unbound-method.test.ts index 50db9e173..cba577d62 100644 --- a/src/rules/__tests__/unbound-method.test.ts +++ b/src/rules/__tests__/unbound-method.test.ts @@ -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(() => { diff --git a/src/rules/unbound-method.ts b/src/rules/unbound-method.ts index eea17ccce..4ec40eafa 100644 --- a/src/rules/unbound-method.ts +++ b/src/rules/unbound-method.ts @@ -7,6 +7,7 @@ import { createRule, findTopMostCallExpression, getAccessorValue, + isIdentifier, parseJestFnCall, } from './utils'; @@ -84,6 +85,14 @@ export default createRule({ context, ); + if ( + jestFnCall?.type === 'jest' && + jestFnCall.members.length >= 1 && + isIdentifier(jestFnCall.members[0], 'mocked') + ) { + return; + } + if (jestFnCall?.type === 'expect') { const { matcher } = jestFnCall;