@@ -8,6 +8,27 @@ import FormAssociatedNoAttachInternals from 'x/formAssociatedNoAttachInternals';
88import FormAssociatedFalseNoAttachInternals from 'x/formAssociatedFalseNoAttachInternals' ;
99import { ENABLE_ELEMENT_INTERNALS_AND_FACE } from '../../../../../helpers/constants.js' ;
1010
11+ const formAssociatedFalsyTest = ( tagName , ctor ) => {
12+ const form = document . createElement ( 'form' ) ;
13+ document . body . appendChild ( form ) ;
14+
15+ const elm = createElement ( `x-${ tagName } ` , { is : ctor } ) ;
16+ form . appendChild ( elm ) ;
17+
18+ const { internals } = elm ;
19+ expect ( ( ) => internals . form ) . toThrow ( ) ;
20+ expect ( ( ) => internals . setFormValue ( '2019-03-15' ) ) . toThrow ( ) ;
21+ expect ( ( ) => internals . willValidate ) . toThrow ( ) ;
22+ expect ( ( ) => internals . validity ) . toThrow ( ) ;
23+ expect ( ( ) => internals . checkValidity ( ) ) . toThrow ( ) ;
24+ expect ( ( ) => internals . reportValidity ( ) ) . toThrow ( ) ;
25+ expect ( ( ) => internals . setValidity ( '' ) ) . toThrow ( ) ;
26+ expect ( ( ) => internals . validationMessage ) . toThrow ( ) ;
27+ expect ( ( ) => internals . labels ) . toThrow ( ) ;
28+
29+ document . body . removeChild ( form ) ;
30+ } ;
31+
1132describe . runIf ( ENABLE_ELEMENT_INTERNALS_AND_FACE && typeof ElementInternals !== 'undefined' ) (
1233 'should throw an error when duplicate tag name used' ,
1334 ( ) => {
@@ -38,30 +59,12 @@ describe.runIf(ENABLE_ELEMENT_INTERNALS_AND_FACE && typeof ElementInternals !==
3859 ) . not . toThrow ( ) ;
3960 } ) ;
4061
41- it ( 'should throw an error when accessing form related properties on a non-form associated component ' , ( ) => {
42- const form = document . createElement ( ' form' ) ;
43- document . body . appendChild ( form ) ;
62+ it ( 'should throw an error when accessing form related properties when formAssociated is false ' , ( ) => {
63+ formAssociatedFalsyTest ( 'x- form-associated-false' , FormAssociatedFalse ) ;
64+ } ) ;
4465
45- const testElements = {
46- 'x-form-associated-false' : FormAssociatedFalse ,
47- 'x-not-form-associated' : NotFormAssociated ,
48- } ;
49- let elm ;
50- Object . entries ( testElements ) . forEach ( ( [ tagName , ctor ] ) => {
51- elm = createElement ( `x-${ tagName } ` , { is : ctor } ) ;
52- const { internals } = elm ;
53- form . appendChild ( elm ) ;
54- expect ( ( ) => internals . form ) . toThrow ( ) ;
55- expect ( ( ) => internals . setFormValue ( '2019-03-15' ) ) . toThrow ( ) ;
56- expect ( ( ) => internals . willValidate ) . toThrow ( ) ;
57- expect ( ( ) => internals . validity ) . toThrow ( ) ;
58- expect ( ( ) => internals . checkValidity ( ) ) . toThrow ( ) ;
59- expect ( ( ) => internals . reportValidity ( ) ) . toThrow ( ) ;
60- expect ( ( ) => internals . setValidity ( '' ) ) . toThrow ( ) ;
61- expect ( ( ) => internals . validationMessage ) . toThrow ( ) ;
62- expect ( ( ) => internals . labels ) . toThrow ( ) ;
63- } ) ;
64- document . body . removeChild ( form ) ;
66+ it ( 'should throw an error when accessing form related properties when formAssociated is undefined' , ( ) => {
67+ formAssociatedFalsyTest ( 'x-not-form-associated' , NotFormAssociated ) ;
6568 } ) ;
6669
6770 it ( 'should be able to use internals to validate form associated component' , ( ) => {
@@ -116,7 +119,7 @@ describe.runIf(ENABLE_ELEMENT_INTERNALS_AND_FACE && typeof ElementInternals !==
116119 }
117120) ;
118121
119- it . runIf ( typeof ElementInternals = == 'undefined' ) (
122+ it . runIf ( typeof ElementInternals ! == 'undefined' ) (
120123 'disallows form association on older API versions' ,
121124 ( ) => {
122125 const isFormAssociated = ( elm ) => {
0 commit comments