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

ぐ巨炮叔叔 提交于 2019-12-11 17:01:15

问题


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


回答1:


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

if (global.document)
  document.createRange = () => ({
    setStart: () => {},
    setEnd: () => {},
    commonAncestorContainer: {
      nodeName: "BODY",
      ownerDocument: document,
    },
  })


来源:https://stackoverflow.com/questions/51887552/jest-enzyme-document-createrange-is-not-a-function-on-mount

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!