Skip to content

Latest commit

 

History

History
48 lines (33 loc) · 1.36 KB

prefer-wait-for.md

File metadata and controls

48 lines (33 loc) · 1.36 KB

Use waitFor instead of deprecated wait methods (prefer-wait-for)

dom-testing-library v7 released a new async util called waitFor which satisfies the use cases of wait, waitForElement, and waitForDomChange making them deprecated.

Rule Details

This rule aims to use waitFor async util rather than previous deprecated ones.

Deprecated wait async utils are:

  • wait
  • waitForElement
  • waitForDomChange

This rule will auto fix deprecated async utils for you, including the necessary empty callback for waitFor. This means wait(); will be replaced with waitFor(() => {});

Examples of incorrect code for this rule:

const foo = async () => {
  await wait();
  await wait(() => {});
  await waitForElement(() => {});
  await waitForDomChange();
  await waitForDomChange(mutationObserverOptions);
  await waitForDomChange({ timeout: 100});
};

Examples of correct code for this rule:

const foo = async () => {
  // new waitFor method
  await waitFor(() => {});

  // previous waitForElementToBeRemoved is not deprecated
  await waitForElementToBeRemoved(() => {});
};

When Not To Use It

When using dom-testing-library (or any other Testing Library relying on dom-testing-library) prior to v7.

Further Reading