Trying to run an unit test for the following code: Using Jest and Enzyme for React Js
After inserting a return into a mock function I keep getting the error: Test cannot read property InnerHTML of null
Here is the mock function: const getCleanJSON = jest.fn (() => { return '{}' })
Without the return , I get the following error: Cannot read property 'appendChild' of null. I am probably missing something inside of my mock Function. Any clues ?
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);
This is the 2nd method where the error is referring to
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)))
)}