Skip to content

Latest commit

 

History

History
63 lines (48 loc) · 1.23 KB

no-await-sync-query.md

File metadata and controls

63 lines (48 loc) · 1.23 KB

Disallow unnecessary await for sync queries (testing-library/no-await-sync-query)

Ensure that sync queries are not awaited unnecessarily.

Rule Details

Usual queries variants that Testing Library provides are synchronous and don't need to wait for any element. Those queries are:

  • getBy*
  • getByAll*
  • queryBy*
  • queryAllBy*

This rule aims to prevent users from waiting for synchronous queries.

Examples of incorrect code for this rule:

const foo = async () => {
  // ...
  const rows = await queryAllByRole('row');
  // ...
};

const bar = () => {
  // ...
  getByText('submit').then(() => {
    // ...
  });
};

const baz = () => {
  // ...
  const button = await screen.getByText('submit');
};

Examples of correct code for this rule:

const foo = () => {
  // ...
  const rows = queryAllByRole('row');
  // ...
};

const bar = () => {
  // ...
  const button = getByText('submit');
  // ...
};

const baz = () => {
  // ...
  const button = screen.getByText('submit');
};

Further Reading