Skip to content

Commit 8753599

Browse files
committed
fix: issue 1800
1 parent 3a2272e commit 8753599

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ const ConsoleClassAndVariableCode = dedent`
4949
const console = new Console();
5050
`;
5151

52+
const ServiceClassAndMethodCode = dedent`
53+
class Service {
54+
method() {}
55+
}
56+
57+
const service = new Service();
58+
`;
59+
5260
const toThrowMatchers = [
5361
'toThrow',
5462
'toThrowError',
@@ -73,6 +81,13 @@ const validTestCases: string[] = [
7381
'expect(() => Promise.resolve().then(console.log)).not.toThrow();',
7482
...toThrowMatchers.map(matcher => `expect(console.log).not.${matcher}();`),
7583
...toThrowMatchers.map(matcher => `expect(console.log).${matcher}();`),
84+
// Issue #1800: jest.mocked().mock.calls should be allowed
85+
...[
86+
'const parameter = jest.mocked(service.method).mock.calls[0][0];',
87+
'const calls = jest.mocked(service.method).mock.calls;',
88+
'const lastCall = jest.mocked(service.method).mock.calls[0];',
89+
'const mockedMethod = jest.mocked(service.method); const parameter = mockedMethod.mock.calls[0][0];',
90+
].map(code => [ServiceClassAndMethodCode, code].join('\n')),
7691
];
7792

7893
const invalidTestCases: Array<TSESLint.InvalidTestCase<MessageIds, Options>> = [
@@ -235,6 +250,7 @@ const arith = {
235250
${code}
236251
`;
237252
}
253+
238254
function addContainsMethodsClassInvalid(
239255
code: string[],
240256
): Array<TSESLint.InvalidTestCase<MessageIds, Options>> {

src/rules/utils/parseJestFnCall.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,9 @@ const parseJestFnCallWithReasonInner = (
338338
// parsing e.g. x().y.z(), we'll incorrectly find & parse "x()" even though
339339
// the full chain is not a valid jest function call chain
340340
if (
341-
node.parent?.type === AST_NODE_TYPES.CallExpression ||
342-
node.parent?.type === AST_NODE_TYPES.MemberExpression
341+
lastLink !== 'mocked' &&
342+
(node.parent?.type === AST_NODE_TYPES.CallExpression ||
343+
node.parent?.type === AST_NODE_TYPES.MemberExpression)
343344
) {
344345
return null;
345346
}

0 commit comments

Comments
 (0)