I've successfully created and injected my stylesheet using JavaScript and I have no issues with the functionality but my tests are now not passing because I get this error
TypeError: Cannot set property 'parentStyleSheet' of undefined .
When I run my tests and console.log(stylesheet), indeed it returns as null.
I can't even get into the first line of my tests because I get this error thrown at me right at the start.
If I comment out my insertRule(), the tests pass.
How can I mock this stylesheet so I can have my tests passing once again?
My function to create a stylesheet:
const createStyleSheet = () => {
this.createdStyleSheet = (function () {
const style = document.createElement('style');
style.title = 'carousel';
style.appendChild(document.createTextNode(''));
document.head.appendChild(style);
return style.sheet;
}());
};
createStyleSheet();
this.createdStyleSheet.insertRule(---stuff inside here---);