I\'m trying to write tests for my web components projects in jest. I already use babel with es2015 preset. I\'m facing an issue while loading the js file. I have followed a
I have resolved this using setUpFiles
property in jest. This will execute after jsdom and before each test which is perfect for me.
Set setupFiles, in Jest config, e.g.:
"setupFiles": ["/browserMock.js"]
// browserMock.js
Object.defineProperty(document, 'currentScript', {
value: document.createElement('script'),
});
Ideal situation would be loading webcomponents.js to polyfill the jsdom.