Skip to content

Commit 80288e2

Browse files
authored
fix(prefer-mock-return-shorthand): ignore async implementations (#1912)
1 parent 1fc7ca0 commit 80288e2

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { FlatCompatRuleTester as RuleTester, espreeParser } from './test-utils';
55
const ruleTester = new RuleTester({
66
parser: espreeParser,
77
parserOptions: {
8-
ecmaVersion: 6,
8+
ecmaVersion: 2017,
99
},
1010
});
1111

@@ -30,6 +30,13 @@ ruleTester.run('prefer-mock-shorthand', rule, {
3030
'jest.fn(() => ({}))',
3131
'aVariable.mockImplementation',
3232
'aVariable.mockImplementation()',
33+
'jest.fn().mockImplementation(async () => 1);',
34+
'jest.fn().mockImplementation(async function () {});',
35+
dedent`
36+
jest.fn().mockImplementation(async function () {
37+
return 42;
38+
});
39+
`,
3340
dedent`
3441
aVariable.mockImplementation(() => {
3542
if (true) {
@@ -350,12 +357,14 @@ ruleTester.run('prefer-mock-shorthand', rule, {
350357
code: dedent`
351358
aVariable
352359
.mockImplementation(() => 42)
360+
.mockImplementation(async () => 42)
353361
.mockImplementation(() => Promise.resolve(42))
354362
.mockReturnValue("hello world")
355363
`,
356364
output: dedent`
357365
aVariable
358366
.mockReturnValue(42)
367+
.mockImplementation(async () => 42)
359368
.mockReturnValue(Promise.resolve(42))
360369
.mockReturnValue("hello world")
361370
`,
@@ -370,7 +379,7 @@ ruleTester.run('prefer-mock-shorthand', rule, {
370379
messageId: 'useMockShorthand',
371380
data: { replacement: 'mockReturnValue' },
372381
column: 4,
373-
line: 3,
382+
line: 4,
374383
},
375384
],
376385
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default createRule({
6161

6262
const [arg] = node.arguments;
6363

64-
if (!isFunction(arg) || arg.params.length !== 0) {
64+
if (!isFunction(arg) || arg.params.length !== 0 || arg.async) {
6565
return;
6666
}
6767

0 commit comments

Comments
 (0)