@happy-dom/jest-environment 8.6.0 → 8.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -47
- package/package.json +2 -2
package/README.md
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|

|
2
2
|
|
3
|
-
|
4
3
|
# About
|
5
4
|
|
6
5
|
[Happy DOM](https://github.com/capricorn86/happy-dom) is a JavaScript implementation of a web browser without its graphical user interface. It includes many web standards from WHATWG [DOM](https://dom.spec.whatwg.org/) and [HTML](https://html.spec.whatwg.org/multipage/).
|
@@ -11,7 +10,6 @@ The goal of [Happy DOM](https://github.com/capricorn86/happy-dom) is to emulate
|
|
11
10
|
|
12
11
|
This package makes it possible to use [Happy DOM](https://github.com/capricorn86/happy-dom) with [Jest](https://jestjs.io/).
|
13
12
|
|
14
|
-
|
15
13
|
### DOM Features
|
16
14
|
|
17
15
|
- Custom Elements (Web Components)
|
@@ -28,8 +26,6 @@ This package makes it possible to use [Happy DOM](https://github.com/capricorn86
|
|
28
26
|
|
29
27
|
And much more..
|
30
28
|
|
31
|
-
|
32
|
-
|
33
29
|
### Works With
|
34
30
|
|
35
31
|
- [Google LitHTML](https://lit-html.polymer-project.org)
|
@@ -42,66 +38,56 @@ And much more..
|
|
42
38
|
|
43
39
|
- [Vue](https://vuejs.org/)
|
44
40
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
41
|
# Installation
|
49
42
|
|
50
43
|
```bash
|
51
44
|
npm install @happy-dom/jest-environment --save-dev
|
52
45
|
```
|
53
46
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
47
|
# Setup
|
58
48
|
|
59
49
|
Jest uses `node` 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 to your Jest config file.
|
60
50
|
|
61
|
-
|
62
|
-
|
63
51
|
## CLI
|
64
52
|
|
65
53
|
1. Edit your "package.json" file.
|
66
54
|
2. Add "--env=@happy-dom/jest-environment" as an attribute to your Jest command.
|
67
55
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
56
|
+
```json
|
57
|
+
{
|
58
|
+
"scripts": {
|
59
|
+
"test": "jest --env=@happy-dom/jest-environment"
|
60
|
+
}
|
61
|
+
}
|
62
|
+
```
|
75
63
|
|
76
64
|
3. Save the file.
|
77
65
|
|
78
|
-
|
79
66
|
## In "package.json"
|
80
67
|
|
81
68
|
1. Edit your "package.json" file.
|
82
69
|
2. Add the following to it:
|
83
70
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
71
|
+
```json
|
72
|
+
{
|
73
|
+
"jest": {
|
74
|
+
"testEnvironment": "@happy-dom/jest-environment"
|
75
|
+
}
|
76
|
+
}
|
77
|
+
```
|
91
78
|
|
92
79
|
3. Save the file.
|
93
80
|
|
94
|
-
|
95
|
-
|
96
81
|
## Configuration File
|
82
|
+
|
97
83
|
1. Edit your Jest config file (usually jest.config.js)
|
98
84
|
2. Add the following to it:
|
99
85
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
86
|
+
```json
|
87
|
+
{
|
88
|
+
"testEnvironment": "@happy-dom/jest-environment"
|
89
|
+
}
|
90
|
+
```
|
105
91
|
|
106
92
|
3. Save the file.
|
107
93
|
|
@@ -109,21 +95,20 @@ Jest uses `node` as test environment by default. In order to tell Jest to use a
|
|
109
95
|
|
110
96
|
Happy DOM exposes two functions that may be useful when testing asynchrounous code.
|
111
97
|
|
112
|
-
|
113
98
|
**whenAsyncComplete()**
|
114
99
|
|
115
100
|
Returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that is resolved when all async tasks has been completed.
|
116
101
|
|
117
102
|
```javascript
|
118
103
|
describe('scrollToTop()', () => {
|
119
|
-
|
120
|
-
|
104
|
+
it('scrolls to top using the built in browser animation', async () => {
|
105
|
+
element.scrollToTop();
|
121
106
|
|
122
|
-
|
123
|
-
|
107
|
+
// Waits for asynchronous tasks like setTimeout(), requestAnimationFrame() etc. to complete
|
108
|
+
await happyDOM.whenAsyncComplete();
|
124
109
|
|
125
|
-
|
126
|
-
|
110
|
+
expect(document.documentElement.scrollTop).toBe(0);
|
111
|
+
});
|
127
112
|
});
|
128
113
|
```
|
129
114
|
|
@@ -133,14 +118,14 @@ This method will cancel all running async tasks.
|
|
133
118
|
|
134
119
|
```javascript
|
135
120
|
describe('runAnimation()', () => {
|
136
|
-
|
137
|
-
|
121
|
+
it('runs animation', () => {
|
122
|
+
element.runAnimation();
|
138
123
|
|
139
|
-
|
140
|
-
|
124
|
+
// Cancels all asynchronous tasks like setTimeout(), requestAnimationFrame() etc.
|
125
|
+
happyDOM.cancelAsync();
|
141
126
|
|
142
|
-
|
143
|
-
|
127
|
+
expect(element.animationCompleted).toBe(true);
|
128
|
+
});
|
144
129
|
});
|
145
130
|
```
|
146
131
|
|
@@ -160,3 +145,6 @@ describe('runAnimation()', () => {
|
|
160
145
|
|
161
146
|
[See how the test was done here](https://github.com/capricorn86/happy-dom-performance-test)
|
162
147
|
|
148
|
+
# Sponsors
|
149
|
+
|
150
|
+
[<img alt="RTVision" width="120px" src="https://avatars.githubusercontent.com/u/8292810?s=200&v=4" />](https://rtvision.com)
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@happy-dom/jest-environment",
|
3
|
-
"version": "8.
|
3
|
+
"version": "8.7.0",
|
4
4
|
"license": "MIT",
|
5
5
|
"homepage": "https://github.com/capricorn86/happy-dom/tree/master/packages/jest-environment",
|
6
6
|
"repository": "https://github.com/capricorn86/happy-dom",
|
@@ -54,7 +54,7 @@
|
|
54
54
|
"@jest/types": "^29.4.0",
|
55
55
|
"jest-mock": "^29.4.0",
|
56
56
|
"jest-util": "^29.4.0",
|
57
|
-
"happy-dom": "^8.
|
57
|
+
"happy-dom": "^8.7.0"
|
58
58
|
},
|
59
59
|
"devDependencies": {
|
60
60
|
"@typescript-eslint/eslint-plugin": "^5.16.0",
|