Ensure that promises returned by fireEvent
methods are awaited
properly.
This rule aims to prevent users from forgetting to await fireEvent
methods when they are async.
Examples of incorrect code for this rule:
fireEvent.click(getByText('Click me'));
fireEvent.focus(getByLabelText('username'));
fireEvent.blur(getByLabelText('username'));
Examples of correct code for this rule:
// `await` operator is correct
await fireEvent.focus(getByLabelText('username'));
await fireEvent.blur(getByLabelText('username'));
// `then` method is correct
fireEvent.click(getByText('Click me')).then(() => {
// ...
});
// return the promise within a function is correct too!
function clickMeRegularFn() {
return fireEvent.click(getByText('Click me'));
}
const clickMeArrowFn = () => fireEvent.click(getByText('Click me'));
fireEvent
methods are only async in Vue Testing Library so if you are using another Testing Library module, you shouldn't use this rule.