From 78ccbefc01720f5c44ae439389cb27afda0315c2 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sat, 20 Aug 2022 09:54:15 +1200 Subject: [PATCH] fix(prefer-mock-promise-shorthand): ignore `mockImplementation` functions that have parameters (#1199) --- src/rules/__tests__/prefer-mock-promise-shorthand.test.ts | 1 + src/rules/prefer-mock-promise-shorthand.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rules/__tests__/prefer-mock-promise-shorthand.test.ts b/src/rules/__tests__/prefer-mock-promise-shorthand.test.ts index 9ae057df7..f74c47011 100644 --- a/src/rules/__tests__/prefer-mock-promise-shorthand.test.ts +++ b/src/rules/__tests__/prefer-mock-promise-shorthand.test.ts @@ -39,6 +39,7 @@ ruleTester.run('prefer-mock-shorthand', rule, { 'aVariable.mockReturnValue(Promise.reject().then(() => 1))', 'aVariable.mockReturnValue(new Promise(resolve => resolve(1)))', 'aVariable.mockReturnValue(new Promise((_, reject) => reject(1)))', + "jest.spyOn(Thingy, 'method').mockImplementation(param => Promise.resolve(param));", dedent` aVariable.mockImplementation(() => { const value = new Date(); diff --git a/src/rules/prefer-mock-promise-shorthand.ts b/src/rules/prefer-mock-promise-shorthand.ts index 47cfde8b2..90cdcba33 100644 --- a/src/rules/prefer-mock-promise-shorthand.ts +++ b/src/rules/prefer-mock-promise-shorthand.ts @@ -112,7 +112,7 @@ export default createRule({ } else if (mockFnName === withOnce('mockImplementation', isOnce)) { const [arg] = node.arguments; - if (!isFunction(arg)) { + if (!isFunction(arg) || arg.params.length !== 0) { return; }