-
-
Notifications
You must be signed in to change notification settings - Fork 179
/
WindowGlobals.test.js
47 lines (44 loc) · 1.47 KB
/
WindowGlobals.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { describe, it, expect } from '../utilities/TestFunctions.js';
import { Window } from 'happy-dom';
describe('WindowGlobals', () => {
it('Functions should have the constructor global.Function.', () => {
const window = new Window();
let error = null;
window.addEventListener('error', (event) => (error = event.error));
window.document.write(`
<script>
if((() => {}).constructor !== Function) {
throw new Error('Error');
}
</script>
`);
expect(error).toBe(null);
});
it('Object should have the constructor global.Object.', () => {
const window = new Window();
let error = null;
window.addEventListener('error', (event) => (error = event.error));
window.document.write(`
<script>
if({}.constructor !== Object) {
throw new Error('Error');
}
</script>
`);
expect(error).toBe(null);
});
it('Binds global methods to the Window context.', () => {
const window = new Window();
let error = null;
window.addEventListener('error', (event) => (error = event.error));
window.document.write(`
<script>
const eventListener = () => {};
addEventListener('click', eventListener);
removeEventListener('click', eventListener);
clearTimeout(setTimeout(eventListener));
</script>
`);
expect(error).toBe(null);
});
});