Skip to content

Commit c2b8515

Browse files
authored
fix(await-async-util): false positives due to empty strings (#733)
1 parent 34a0a55 commit c2b8515

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

lib/rules/await-async-utils.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,16 @@ export default createTestingLibraryRule<Options, MessageIds>({
4444

4545
function detectAsyncUtilWrapper(node: TSESTree.Identifier) {
4646
const innerFunction = getInnermostReturningFunction(context, node);
47+
if (!innerFunction) {
48+
return;
49+
}
4750

48-
if (innerFunction) {
49-
functionWrappersNames.push(getFunctionName(innerFunction));
51+
const functionName = getFunctionName(innerFunction);
52+
if (functionName.length === 0) {
53+
return;
5054
}
55+
56+
functionWrappersNames.push(functionName);
5157
}
5258

5359
/*

tests/lib/rules/await-async-utils.test.ts

+32
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,38 @@ ruleTester.run(RULE_NAME, rule, {
292292
293293
await setup().waitForAsyncUtil();
294294
});
295+
`,
296+
})),
297+
...ASYNC_UTILS.map((asyncUtil) => ({
298+
code: `
299+
import React from 'react';
300+
import { render, act } from '@testing-library/react';
301+
302+
const doWithAct = async (timeout) => {
303+
await act(async () => await ${asyncUtil}(screen.getByTestId('my-test')));
304+
};
305+
306+
describe('Component', () => {
307+
const mock = jest.fn();
308+
309+
it('test', async () => {
310+
let Component = () => {
311+
mock(1);
312+
return <div />;
313+
};
314+
render(<Component />);
315+
316+
await doWithAct(500);
317+
318+
const myNumberTestVar = 1;
319+
const myBooleanTestVar = false;
320+
const myArrayTestVar = [1, 2];
321+
const myStringTestVar = 'hello world';
322+
const myObjectTestVar = { hello: 'world' };
323+
324+
expect(mock).toHaveBeenCalledWith(myNumberTestVar);
325+
});
326+
});
295327
`,
296328
})),
297329
]),

0 commit comments

Comments
 (0)