Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { Window } from 'happy-dom';
const window = new Window();
for (const key of [
'self',
'document',
'HTMLElement',
'HTMLUnknownElement',
'customElements'
]) {
// @ts-ignore
global[key] = window[key];
}
self.requestAnimationFrame = setTimeout;
//https://github.com/unrealprogrammer/how-to-test-web-component
const { Window } = require('happy-dom');
const window = new Window();
const _fetch = require('jest-fetch-mock');
window.document.createElementNS = function() {
if(arguments.length === 1) {
return window.document.createElement(arguments[0]);
} else {
return window.document.createElement(arguments[1]);
}
};
const _CSSStyleSheet = jest.fn();
window.CSSStyleSheet = _CSSStyleSheet;
window.fetch = _fetch;
Object.assign(global, {
document: window.document,