2

I am using react-testing-library with jest-dom. It is working fine but when i try to use toBeInTheDocument it throws the error TypeError: element.getRootNode is not a function.

expect(getByText('Not in dom')).not.toBeInTheDocument(); // It works
expect(getByText('Value in DOM')).toBeInTheDocument();  // It throws the error

Error log:

TypeError: element.getRootNode is not a function
      
      at Object.it (src/x/y/z.test.js:42:34)
          at new Promise (<anonymous>)
      at process._tickCallback (internal/process/next_tick.js:68:7)
6
  • Do you have jest.config.js in your project? if you have share this file too. Commented Jun 18, 2021 at 8:35
  • No I dont have this file I am using default create-react-app config. Commented Jun 18, 2021 at 9:02
  • 1
    Could you share all the test code? Commented Jun 19, 2021 at 1:35
  • 1
    I am running into the same issue. Any tricks on how to circumvent that? Commented Sep 23, 2021 at 10:22
  • 1
    Had the same issue, @testing-library/jest-dom version 5.x.x was causing the problem, using 4.x.x without any errors atm. Commented Nov 8, 2021 at 19:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.