Skip to content

Latest commit

 

History

History
40 lines (30 loc) · 1.2 KB

no-wait-for-empty-callback.md

File metadata and controls

40 lines (30 loc) · 1.2 KB

Empty callbacks inside waitFor and waitForElementToBeRemoved are not preferred (no-wait-for-empty-callback)

Rule Details

This rule aims to ensure the correct usage of waitFor and waitForElementToBeRemoved, in the way that they're intended to be used. If an empty callback is passed, these methods will just wait next tick of the event loop before proceeding, and that's not consistent with the philosophy of the library. Instead, insert an assertion in that callback function.

Examples of incorrect code for this rule:

const foo = async () => {
  await waitFor(() => {});
  await waitFor(function() {});
  await waitFor(noop);

  await waitForElementToBeRemoved(() => {});
  await waitForElementToBeRemoved(function() {});
  await waitForElementToBeRemoved(noop);
};

Examples of correct code for this rule:

const foo = async () => {
  await waitFor(() => {
    screen.getByText(/submit/i);
  });

  const submit = screen.getByText(/submit/i);
  await waitForElementToBeRemoved(() => submit);
  // or
  await waitForElementToBeRemoved(submit);
};

Further Reading