forked from calebdwilliams/element-internals-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsdom.test.js
36 lines (28 loc) · 1.12 KB
/
jsdom.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
import { JSDOM } from 'jsdom';
import { readFileSync } from 'fs';
const polyfillContents = readFileSync('./dist/index.js', 'utf-8');
function test(title, condition) {
if (!condition) {
throw new Error(`${title} failed with error ${error}`);
} else {
console.log(`${title} passed in JSDOM`);
}
}
JSDOM.fromFile('./jsdom-tests/index.html', {
runScripts: 'dangerously'
}).then(async ({ window }) => {
const document = window._document;
const polyfill = document.createElement('script');
polyfill.textContent = polyfillContents;
document.body.append(polyfill);
const form = document.createElement('form');
const testElement = document.createElement('test-element');
testElement.setAttribute('name', 'test');
form.append(testElement);
document.body.append(form);
setImmediate(async () => {
test('ElementInternals is defined on the window', typeof window.ElementInternals !== 'undefined');
test('Polyfilled ElementInternals.prototype.form is working', testElement.internals.form === form);
test('Polyfilled form attachment is working', new window.FormData(form).get('test') === 'foo');
});
});