testing-library / dom-testing-library

🐙 Simple and complete DOM testing utilities that encourage good testing practices.
https://testing-library.com/dom
MIT License
3.26k stars 467 forks source link

Behavior of waitForElementToBeRemoved when first call throws #1093

Open make-github-pseudonymous-again opened 2 years ago

make-github-pseudonymous-again commented 2 years ago

Problem description:

There is currently no exception catching for the initial call inside waitForElementToBeRemoved. When that call of callback throws, instead of getting the error Error('The element(s) given to waitForElementToBeRemoved are already removed...') we will get the error thrown from the callback, even when it is a TestingLibraryElementError. This contradicts the documented behavior:

waitForElementToBeRemoved(() => getByText(/not here/i)).catch(err =>
  console.log(err),
)
// Error: The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal.

Suggested solution:

See #1094.

eps1lon commented 2 years ago

This contradicts the documented behavior:

The documentation is contradicting itself already. It only says that it'll throw on null or empty arrays. But it doesn't say that () => null will throw. However, it later includes waitForElementToBeRemoved(() => getByText(/not here/i)) in the examples.

So documentation should be clarified as well.