Skip to content

Latest commit

 

History

History
67 lines (50 loc) · 1.36 KB

no-await-sync-queries.md

File metadata and controls

67 lines (50 loc) · 1.36 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.

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