我正在使用react-test-renderer 中的createMockNode 并模拟了样式以防止未定义的错误。
let createNodeMock = (element) => {
if (element.type === 'input') {
return {
style: {"color":"red"},
};
}
return null;
}
这防止了样式上的“未定义”错误,但现在我收到了这个错误:
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)
(顺便说一句,我正在我的组件中测试react-bootstrap-typeahead。)
我是否正确地为输入创建了模拟对象?