How to use the happy-dom.Window function in happy-dom

To help you get started, we’ve selected a few happy-dom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github EasyWebApp / WebCell / MobX / source / DOM-polyfill.ts View on Github external
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;
github KiranMantha / plumejs / testBed / mocks / jestSetup.js View on Github external
//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,

happy-dom

Happy DOM is a JavaScript implementation of a web browser without its graphical user interface. It includes many web standards from WHATWG DOM and HTML.

MIT
Latest version published 27 days ago

Package Health Score

91 / 100
Full package analysis

Popular happy-dom functions