Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

waitForElementToBeRemoved is timing out when passed an element

I'm trying to use waitForElementToBeRemoved with just an element but Jest is timing out. When I pass in a function, it works.

My understanding from this feature was that it should be able to take an element: https://github.com/testing-library/dom-testing-library/pull/460

I verified my app is using @testing-library/[email protected].

Here's the code:

// doesn't work
await waitForElementToBeRemoved(screen.getByText("Loading..."));

// works
await waitForElementToBeRemoved(() => screen.getByText("Loading..."));

Any idea what I'm doing wrong?

like image 464
Sam Selikoff Avatar asked Jun 02 '20 17:06

Sam Selikoff


1 Answers

Recently I faced the same issue with React Testing Library, and the reason is the version of the library. By default create-react-app installing outdated version of @testing-library.
Here solution for React Testing Library:
Run CLI command npm outdated and check the versions of dependencies:

Package                      Current  Wanted  Latest
@testing-library/jest-dom      4.2.4   4.2.4  5.11.4
@testing-library/react         9.5.0   9.5.0  11.0.2
@testing-library/user-event    7.2.1   7.2.1  12.1.4

To update dependencies open package.json and manually update them to the latest:

  ...
  "dependencies": {
    ...
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.0.2",
    "@testing-library/user-event": "^12.1.4"
    ...
  },
  ...

Save changes and run CLI command: npm install

In case DOM Testing Library use the same steps for "@testing-library/dom"

like image 50
Alex G. Avatar answered Oct 23 '22 13:10

Alex G.