Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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