Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(unbound-method): ignore functions passed to jest.mocked #1681

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 10 additions & 0 deletions src/rules/unbound-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ export default createRule<Options, MessageIds>({
...baseSelectors,
MemberExpression(node: TSESTree.MemberExpression): void {
if (node.parent?.type === AST_NODE_TYPES.CallExpression) {
if (
node.parent.callee.type === AST_NODE_TYPES.MemberExpression &&
node.parent.callee.object.type === AST_NODE_TYPES.Identifier &&
node.parent.callee.object.name === 'jest' &&
node.parent.callee.property.type === AST_NODE_TYPES.Identifier &&
node.parent.callee.property.name === 'mocked'
) {
return;
}
FloEdelmann marked this conversation as resolved.
Show resolved Hide resolved

const jestFnCall = parseJestFnCall(
findTopMostCallExpression(node.parent),
context,
Expand Down
Loading