Skip to content

Commit 9af08e9

Browse files
fix: respond to changes to the name attribute and naive jsdom tests
1 parent da3306f commit 9af08e9

File tree

7 files changed

+1138
-212
lines changed

7 files changed

+1138
-212
lines changed

Diff for: jsdom-tests/index.html

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Test document in JSDOM</title>
5+
<!--script>${polyfillContents};console.log(ElementInternals)</script-->
6+
<script src="polyfill.js"></script>
7+
</head>
8+
<body>
9+
<script>
10+
class TestElement extends HTMLElement {
11+
static get formAssociated() {
12+
return true;
13+
}
14+
15+
constructor() {
16+
super();
17+
this.internals = this.attachInternals();
18+
this.internals.setFormValue('foo');
19+
}
20+
}
21+
22+
customElements.define('test-element', TestElement);
23+
</script>
24+
</body>
25+
</html>

Diff for: jsdom-tests/jsdom.test.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { JSDOM } from 'jsdom';
2+
import { readFileSync } from 'fs';
3+
4+
const polyfillContents = readFileSync('./dist/index.js', 'utf-8');
5+
6+
function test(title, condition) {
7+
if (!condition) {
8+
throw new Error(`${title} failed with error ${error}`);
9+
} else {
10+
console.log(`${title} passed in JSDOM`);
11+
}
12+
}
13+
14+
JSDOM.fromFile('./jsdom-tests/index.html', {
15+
runScripts: 'dangerously'
16+
}).then(async ({ window }) => {
17+
const document = window._document;
18+
19+
const polyfill = document.createElement('script');
20+
polyfill.textContent = polyfillContents;
21+
22+
document.body.append(polyfill);
23+
24+
const form = document.createElement('form');
25+
const testElement = document.createElement('test-element');
26+
testElement.setAttribute('name', 'test');
27+
28+
form.append(testElement);
29+
document.body.append(form);
30+
31+
setImmediate(async () => {
32+
test('ElementInternals is defined on the window', typeof window.ElementInternals !== 'undefined');
33+
test('Polyfilled ElementInternals.prototype.form is working', testElement.internals.form === form);
34+
test('Polyfilled form attachment is working', new window.FormData(form).get('test') === 'foo');
35+
});
36+
});

0 commit comments

Comments
 (0)