eslint-plugin-testing-library/await-async-events for method calls on user-event instances created with setup() #1072
Replies: 2 comments
|
Hey @spicattutti! If you are using TS, what about |
|
So I would solve this at the TypeScript promise level, not with // eslint.config.js
export default tseslint.config(
// ...your other config
{
files: ["**/test/**/*.test.{ts,tsx}"],
rules: {
"@typescript-eslint/no-floating-promises": "error",
},
},
);Then make sure the helper preserves the real setup return type instead of widening it: import userEvent from "@testing-library/user-event";
type RenderWithThemeResult = {
user: ReturnType<typeof userEvent.setup>;
// other render result fields...
};With that, forgotten awaits like this should be caught because user.click(button); // no-floating-promises error
await user.click(button); // okIf you have intentional fire-and-forget cases, mark them explicitly with One tradeoff: |
Uh oh!
There was an error while loading. Please reload this page.
Context
await-async-eventsdoes not enforce missing awaits foruser.click()(whereuseris created like shown above, only for the case of using exported APIsProblem
click,typeetc using TS and eslint without enablingrequire-await, which would be painful to enableTS test helpers:
eslint config:
userEventobject in our test helper in case of no override for options, because the setup call is recommended, as mentioned aboveQuestion
Has anyone solved this?
All reactions