Skip to content

Commit da4b6f7

Browse files
authored
fix(prefer-mock-return-shorthand): ignore use of update expressions (#858)
1 parent d15371f commit da4b6f7

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/rules/prefer-mock-return-shorthand.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ export default createEslintRule<Options, MESSAGE_IDS>({
7171

7272
const returnNode = findSingleReturnArgumentNode(arg)
7373

74-
if (!returnNode) {
74+
if (
75+
!returnNode ||
76+
returnNode.type === AST_NODE_TYPES.UpdateExpression
77+
) {
7578
return
7679
}
7780

tests/prefer-mock-return-shorthand.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,28 @@ ruleTester.run(RULE_NAME, rule, {
3131
return 2;
3232
});
3333
`,
34+
'aVariable.mockImplementation(() => value++)',
35+
'aVariable.mockImplementationOnce(() => --value)',
36+
`
37+
const aValue = 0;
38+
aVariable.mockImplementation(() => {
39+
return aValue++;
40+
});
41+
`,
42+
`
43+
aVariable.mockImplementation(() => {
44+
aValue += 1;
45+
46+
return aValue;
47+
});
48+
`,
49+
`
50+
aVariable.mockImplementation(() => {
51+
aValue++;
52+
53+
return aValue;
54+
});
55+
`,
3456
'aVariable.mockReturnValue()',
3557
'aVariable.mockReturnValue(1)',
3658
'aVariable.mockReturnValue("hello world")',

0 commit comments

Comments
 (0)