Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest/Enzyme document.createRange is not a function on mount

When trying to use ezymes mount on a component that is rendering MaterialUI's Tooltip, there is an error stopping my tests:

TypeError: document.createRange is not a function

like image 430
Eric Stermer Avatar asked Dec 03 '22 11:12

Eric Stermer


1 Answers

To fix this I defined document.createRange in my ./src/setupTest.js

  document.createRange = () => ({
    setStart: () => {},
    setEnd: () => {},
    commonAncestorContainer: {
      nodeName: "BODY",
      ownerDocument: document,
    },
  })
like image 57
Eric Stermer Avatar answered Jan 12 '23 00:01

Eric Stermer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!