Skip to content

Commit

Permalink
fix(await-async-util): false positives due to empty strings (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
patriscus committed Feb 15, 2023
1 parent 34a0a55 commit c2b8515
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/rules/await-async-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,16 @@ export default createTestingLibraryRule<Options, MessageIds>({

function detectAsyncUtilWrapper(node: TSESTree.Identifier) {
const innerFunction = getInnermostReturningFunction(context, node);
if (!innerFunction) {
return;
}

if (innerFunction) {
functionWrappersNames.push(getFunctionName(innerFunction));
const functionName = getFunctionName(innerFunction);
if (functionName.length === 0) {
return;
}

functionWrappersNames.push(functionName);
}

/*
Expand Down
32 changes: 32 additions & 0 deletions tests/lib/rules/await-async-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,38 @@ ruleTester.run(RULE_NAME, rule, {
await setup().waitForAsyncUtil();
});
`,
})),
...ASYNC_UTILS.map((asyncUtil) => ({
code: `
import React from 'react';
import { render, act } from '@testing-library/react';
const doWithAct = async (timeout) => {
await act(async () => await ${asyncUtil}(screen.getByTestId('my-test')));
};
describe('Component', () => {
const mock = jest.fn();
it('test', async () => {
let Component = () => {
mock(1);
return <div />;
};
render(<Component />);
await doWithAct(500);
const myNumberTestVar = 1;
const myBooleanTestVar = false;
const myArrayTestVar = [1, 2];
const myStringTestVar = 'hello world';
const myObjectTestVar = { hello: 'world' };
expect(mock).toHaveBeenCalledWith(myNumberTestVar);
});
});
`,
})),
]),
Expand Down

0 comments on commit c2b8515

Please sign in to comment.