-
-
Notifications
You must be signed in to change notification settings - Fork 178
/
Bun.test.js
89 lines (74 loc) · 1.83 KB
/
Bun.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { GlobalRegistrator } from '../../lib/index.js';
import { test, expect } from 'bun:test';
GlobalRegistrator.register();
/* eslint-disable no-undef */
const GETTERS = [
'location',
'history',
'navigator',
'screen',
'sessionStorage',
'localStorage',
'opener',
'scrollX',
'pageXOffset',
'scrollY',
'pageYOffset',
'CSS',
'innerWidth',
'innerHeight',
'outerWidth',
'outerHeight',
'devicePixelRatio'
];
test('DOM', () => {
document.body.innerHTML = `<button>My button</button>`;
const button = document.querySelector('button');
expect(button?.innerText).toEqual('My button');
});
test('CSS', () => {
const style = document.createElement('style');
document.head.appendChild(style);
style.innerHTML = `
body {
background-color: red;
}
@media (min-width: 1000px) {
body {
background-color: green;
}
}
`;
expect(globalThis.getComputedStyle(document.body).backgroundColor).toBe('green');
});
test('Window getters', () => {
const included = [];
const propertyNames = Object.getOwnPropertyNames(global);
for (const name of GETTERS) {
if (propertyNames.includes(name)) {
included.push(name);
}
}
expect(included).toEqual(GETTERS);
});
test('Window location', () => {
globalThis.location.href = 'https://example.com/';
expect(globalThis.location.href).toBe('https://example.com/');
});
test('Window options', () => {
GlobalRegistrator.unregister();
GlobalRegistrator.register({
url: 'https://example.com/',
width: 1920,
height: 1080,
settings: {
navigator: {
userAgent: 'Custom User Agent'
}
}
});
expect(globalThis.location.href).toBe('https://example.com/');
expect(globalThis.innerWidth).toBe(1920);
expect(globalThis.innerHeight).toBe(1080);
expect(globalThis.navigator.userAgent).toBe('Custom User Agent');
});