Skip to content

Latest commit

 

History

History
69 lines (51 loc) · 1.5 KB

no-await-sync-queries.md

File metadata and controls

69 lines (51 loc) · 1.5 KB

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

💼 This rule is enabled in the following configs: angular, dom, marko, react, vue.

🔧 This rule is automatically fixable by the --fix CLI option.

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