Cannot read property '_ownerDocument' of undefined while mocking ref

风格不统一 提交于 2019-12-11 15:37:09

问题


I am using createMockNode from react-test-renderer and have mocked out the style to prevent undefined errors.

let createNodeMock = (element) => {
    if (element.type === 'input') {
        return {
            style: {"color":"red"},
        };
    }
    return null;
}

This has prevented the "undefined" error on style, but now I get this error :

TypeError: Cannot read property '_ownerDocument' of undefined
        at unstable_runWithPriority (A:\frontend\node_modules\scheduler\cjs\scheduler.development.js:643:12) TypeError: Cannot read property '_ownerDocument' of undefined
        at exports.matchesDontThrow (A:\frontend\node_modules\jest-environment-jsdom\node_modules\jsdom\lib\jsdom\living\helpers\selectors.js:8:27)
        at setPropertiesFromRule (A:\frontend\node_modules\jest-environment-jsdom\node_modules\jsdom\lib\jsdom\browser\Window.js:536:72)
        at forEach.call.rule (A:\frontend\node_modules\jest-environment-jsdom\node_modules\jsdom\lib\jsdom\browser\Window.js:552:11)

(BTW, I am testing react-bootstrap-typeahead inside my component.)

Am I correctly creating the mock object for the input?

来源:https://stackoverflow.com/questions/58234007/cannot-read-property-ownerdocument-of-undefined-while-mocking-ref

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