`await-async-events` reports a problem when `userEvent.setup` is called from another function
dfernandez79 opened this issue ยท 4 comments
dfernandez79 commented
Have you read the Troubleshooting section?
Yes
Plugin version
v6.0.2
ESLint version
v8.50.0
Node.js version
18.18.0
package manager and version
npm 9.8.1
Operating system
macOS Ventura 13.5.2 (22G91)
Bug description
The rule await-async-events with Promise returned from setUpUserEvents wrapper over async event method must be handled when I call userEvent.setup() from setUpUserEvents.
Example:
import userEvent, { type UserEvent } from '@testing-library/user-event';
const setUpUserEvents = (): UserEvent =>
userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
test('Something', async () => {
const { click } = setUpUserEvents();
/* ... */
await click(someElement);
});Steps to reproduce
- Create a test that uses
userEvent.setup() - Run lint w/
await-async-events(all ok) - Refactor the call to
userEvent.setup()into another function - Run lint w/
await-async-events(eslint fails)
Error output/screenshots
After the refactor (eslint error):

Eslint error:
error Promise returned from `setUpUserEvents` wrapper over async event method must be handled testing-library/await-async-events
ESLint configuration
I'm extending AirBnb rules with:
{
files: ['**/*.test.ts?(x)'],
env: {
jest: true,
},
extends: ['plugin:testing-library/react', 'plugin:jest-dom/recommended'],
},
Rule(s) affected
testing-library/await-async-events
Anything else?
The PR #817 is checking for the name setup.
Maybe that isn't enough.
Do you want to submit a pull request to fix this bug?
No
shoota commented
we have same problem like below in v6.0.2
const setup = () => {
const utils = render(<SomeComponent />,);
const user = userEvent.setup(); // error, `Promise returned from async event method `user` must be handled`
return { ...utils, user};
};
...
describe('test suit', () => {
it('case', async () => {
const user = userEvent.setup(); // no errorsidrak19 commented
We are getting a similar issue to what @shoota mentioned above, is there any different way/fix for doing this?
trungutt commented
