About
A JSDOM alternative with support for server side rendering of web components.
Happy DOM aims to support all common functionality of a web browser.
This package makes it possible to use Happy DOM with Jest.
DOM Features
And much more..
Works With
Installation
npm install @happy-dom/jest-environment --save-dev
Setup
Jest uses JSDOM as test environment by default. In order to tell Jest to use a different environment we will either have to set a CLI attribute, define it in "package.json" or add a property your Jest config file.
CLI
-
Edit your "package.json" file.
-
Add "--env=jest-environment-happy-dom" as an attribute to your Jest command.
{
"scripts": {
"test": "jest --env=jest-environment-happy-dom"
}
}
-
Save the file.
In "package.json"
-
Edit your "package.json" file.
-
Add the following to it:
{
"jest": {
"testEnvironment": "jest-environment-happy-dom"
}
}
-
Save the file.
Configuration File
-
Edit your Jest config file (usually jest.config.js)
-
Add the following to it:
{
"testEnvironment": "jest-environment-happy-dom"
}
-
Save the file.