Use Happy DOM globally in a Node.js environment for testing.
npm install @happy-dom/global-registratorThis package makes it possible to register Happy DOM and makes it easy to setup your own test environment.
``bash`
npm install @happy-dom/global-registrator --save-dev
You will find the documentation in the Happy DOM Wiki under Global Registrator.
#### Register
`javascript
import { GlobalRegistrator } from '@happy-dom/global-registrator';
GlobalRegistrator.register({ url: 'http://localhost:3000', width: 1920, height: 1080 });
document.body.innerHTML = ;
const button = document.querySelector('button');
// Outputs: "My button"
console.log(button.innerText);
`
#### Unregister
`javascript
import { GlobalRegistrator } from '@happy-dom/global-registrator';
GlobalRegistrator.register();
await GlobalRegistrator.unregister();
// Outputs: "undefined"
console.log(global.document);
``
Documentation | Getting Started | Setup as Test Environment | GitHub