|
1 | 1 | import { assert } from '@open-wc/testing';
|
2 |
| -import { h, createContext } from 'preact'; |
| 2 | +import { h, createContext, Component } from 'preact'; |
3 | 3 | import { useContext } from 'preact/hooks';
|
4 | 4 | import { act } from 'preact/test-utils';
|
5 | 5 | import registerElement from './index';
|
@@ -279,4 +279,34 @@ describe('web components', () => {
|
279 | 279 | root.appendChild(el);
|
280 | 280 | assert.isTrue(el.shadowRoot === null);
|
281 | 281 | });
|
| 282 | + |
| 283 | + it('supports the `formAssociated` property', async () => { |
| 284 | + class FormAssociatedClass extends Component { |
| 285 | + static formAssociated = true; |
| 286 | + |
| 287 | + render() { |
| 288 | + return <input name="foo" />; |
| 289 | + } |
| 290 | + } |
| 291 | + registerElement(FormAssociatedClass, 'x-form-associated-class', []); |
| 292 | + |
| 293 | + function FormAssociatedFunction() { |
| 294 | + return <input name="bar" />; |
| 295 | + } |
| 296 | + FormAssociatedFunction.formAssociated = true; |
| 297 | + registerElement(FormAssociatedFunction, 'x-form-associated-function', []); |
| 298 | + |
| 299 | + root.innerHTML = ` |
| 300 | + <form id="myForm"> |
| 301 | + <x-form-associated-class></x-form-associated-class> |
| 302 | + <x-form-associated-function></x-form-associated-function> |
| 303 | + </form> |
| 304 | + `; |
| 305 | + |
| 306 | + const myForm = document.getElementById('myForm'); |
| 307 | + |
| 308 | + // The `.elements` property of a form includes all form-associated elements |
| 309 | + assert.equal(myForm.elements[0].tagName, 'X-FORM-ASSOCIATED-CLASS'); |
| 310 | + assert.equal(myForm.elements[2].tagName, 'X-FORM-ASSOCIATED-FUNCTION'); |
| 311 | + }); |
282 | 312 | });
|
0 commit comments