npm.io
20.10.6 • Published 1 month ago

@happy-dom/global-registrator

Licence
MIT
Version
20.10.6
Deps
0
Vulns
0
Weekly
0
Stars
4.6K

Happy DOM Logo

This package makes it possible to register Happy DOM and makes it easy to setup your own test environment.

Installation

npm install @happy-dom/global-registrator --save-dev

Documentation

You will find the documentation in the Happy DOM Wiki under Global Registrator.

Usage

Register
import { GlobalRegistrator } from '@happy-dom/global-registrator';

GlobalRegistrator.register({ url: 'http://localhost:3000', width: 1920, height: 1080 });

document.body.innerHTML = `<button>My button</button>`;

// Outputs: "My button"
console.log(document.querySelector('button').innerText);

or register on import with default settings:

import '@happy-dom/global-registrator/register.js';

// Settings can be accessed and modified via the global "happyDOM" object
window.happyDOM.setURL('http://localhost:3000');
window.happyDOM.settings.happyDOM.settings.navigator.maxTouchPoints = 0;

document.body.innerHTML = `<button>My button</button>`;

// Outputs: "My button"
console.log(document.querySelector('button').innerText);
Unregister
import { GlobalRegistrator } from '@happy-dom/global-registrator';

GlobalRegistrator.register();

await GlobalRegistrator.unregister();

// Outputs: "undefined"
console.log(global.document);

Happy DOM

Documentation | Getting Started | Setup as Test Environment | GitHub

Keywords