【发布时间】:2019-08-09 06:36:18
【问题描述】:
尝试对以下代码运行单元测试:Using Jest and Enzyme for React Js
在模拟函数中插入返回后,我不断收到错误消息: 测试无法读取 null 的属性 InnerHTML
这是模拟函数: const getCleanJSON = jest.fn (() => { return '{}' })
如果没有 return ,我会收到以下错误:无法读取 null 的属性“appendChild”。我可能在我的模拟函数中遗漏了一些东西。有什么线索吗?
const s = document.createElement('script');
s.id = 'script'
s.type = 'text/template';
s.async = true;
s.innerHTML = script;
this.instance.appendChild(s);
this.renderView(serverSideRender);
这是错误所指的第二种方法
renderview() {
.....
return (
engine.parseAndRender( document.getElementById('script').innerHTML, cleanJSON)
.then( (html) => {
if(document.getElementById('result')){
document.getElementById('result').innerHTML = html == 'null'? '': html
}
}
)
.catch(e => document.getElementById('result').innerHTML = pretty(this.escapeHTML(e.stack)))
)}
【问题讨论】:
标签: reactjs jestjs enzyme appendchild