Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

eslint-plugin-testing-library/await-async-events for method calls on user-event instances created with setup() #1072

Unanswered
spicattutti asked this question in Q&A
Discussion options

Context

const { user } = renderWithTheme(<FooComponent/>, {
 userEventOptions: {
 delay: 1,
 },
 });
  • we have flaky tests because await-async-events does not enforce missing awaits for user.click() (where user is created like shown above, only for the case of using exported APIs
import userEvent from "@testing-library/user-event";
userEvent.click // eslint complains

Problem

  • we get flaky tests because of forgotten awaits
  • we cannot enforce using await on click, type etc using TS and eslint without enabling require-await, which would be painful to enable

TS test helpers:

// import type { Asyncify } from "type-fest";
type UserSetupResult = Omit<
 ReturnType<typeof userEvent.setup>,
 "click" | "type"
> & {
 click: Asyncify<typeof userEvent.click>;
 type: Asyncify<typeof userEvent.type>;
 // ...
};

eslint config:

 // use base rule (instead of `@typescript-eslint/require-await` to speed up runs
 "require-await": "error",
  • we can also not just return the raw userEvent object in our test helper in case of no override for options, because the setup call is recommended, as mentioned above

Question

Has anyone solved this?

You must be logged in to vote

Replies: 1 comment

Comment options

Hey @spicattutti! If you are using TS, what about @typescript-eslint/no-floating-promises rule?

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /