@@ -35,7 +35,7 @@ const expectedEveryError = {
35
35
} ;
36
36
37
37
38
- const array = [ {
38
+ const optionsComponents = [ {
39
39
components : [ 'Label' , 'Descriptor' ] ,
40
40
} ] ;
41
41
const optionsRequiredNesting = [ {
@@ -63,18 +63,18 @@ ruleTester.run('label-has-for', rule, {
63
63
{ code : '<UX.Layout>test</UX.Layout>' } ,
64
64
65
65
// CUSTOM ELEMENT ARRAY OPTION TESTS
66
- { code : '<Label htmlFor="foo" />' , options : [ assign ( { } , array [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
67
- { code : '<Label htmlFor={"foo"} />' , options : [ assign ( { } , array [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
68
- { code : '<Label htmlFor={foo} />' , options : [ assign ( { } , array [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
69
- { code : '<Label htmlFor={`${id}`} />' , options : [ assign ( { } , array [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
70
- { code : '<div />' , options : array } ,
71
- { code : '<Label htmlFor="something"><input /></Label>' , options : array } ,
72
- { code : '<Label htmlFor="foo">Test!</Label>' , options : [ assign ( { } , array [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
73
- { code : '<Descriptor htmlFor="foo" />' , options : [ assign ( { } , array [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
74
- { code : '<Descriptor htmlFor={"foo"} />' , options : [ assign ( { } , array [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
75
- { code : '<Descriptor htmlFor={foo} />' , options : [ assign ( { } , array [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
76
- { code : '<Descriptor htmlFor={`${id}`} />' , options : [ assign ( { } , array [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
77
- { code : '<Descriptor htmlFor="foo">Test!</Descriptor>' , options : [ assign ( { } , array [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
66
+ { code : '<Label htmlFor="foo" />' , options : [ assign ( { } , optionsComponents [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
67
+ { code : '<Label htmlFor={"foo"} />' , options : [ assign ( { } , optionsComponents [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
68
+ { code : '<Label htmlFor={foo} />' , options : [ assign ( { } , optionsComponents [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
69
+ { code : '<Label htmlFor={`${id}`} />' , options : [ assign ( { } , optionsComponents [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
70
+ { code : '<div />' , options : optionsComponents } ,
71
+ { code : '<Label htmlFor="something"><input /></Label>' , options : optionsComponents } ,
72
+ { code : '<Label htmlFor="foo">Test!</Label>' , options : [ assign ( { } , optionsComponents [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
73
+ { code : '<Descriptor htmlFor="foo" />' , options : [ assign ( { } , optionsComponents [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
74
+ { code : '<Descriptor htmlFor={"foo"} />' , options : [ assign ( { } , optionsComponents [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
75
+ { code : '<Descriptor htmlFor={foo} />' , options : [ assign ( { } , optionsComponents [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
76
+ { code : '<Descriptor htmlFor={`${id}`} />' , options : [ assign ( { } , optionsComponents [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
77
+ { code : '<Descriptor htmlFor="foo">Test!</Descriptor>' , options : [ assign ( { } , optionsComponents [ 0 ] , optionsRequiredSome [ 0 ] ) ] } ,
78
78
{ code : '<label htmlFor="foo" />' , options : optionsRequiredSome } ,
79
79
{ code : '<label htmlFor={"foo"} />' , options : optionsRequiredSome } ,
80
80
{ code : '<label htmlFor={foo} />' , options : optionsRequiredSome } ,
@@ -84,82 +84,125 @@ ruleTester.run('label-has-for', rule, {
84
84
{ code : '<label><input /></label>' , options : optionsRequiredNesting } ,
85
85
{ code : '<label htmlFor="input"><input /></label>' , options : optionsRequiredEvery } ,
86
86
{ code : '<label><input /></label>' , options : optionsChildrenAllowed } ,
87
- { code : '<Descriptor htmlFor="foo">Test!</Descriptor>' , options : [ assign ( { } , array , optionsChildrenAllowed ) ] } ,
87
+ { code : '<Descriptor htmlFor="foo">Test!</Descriptor>' , options : [ assign ( { } , optionsComponents , optionsChildrenAllowed ) ] } ,
88
88
{ code : '<label>Test!</label>' , options : optionsChildrenAllowed } ,
89
89
{ code : '<label htmlFor="foo">Test!</label>' , options : optionsChildrenAllowed } ,
90
90
{ code : '<label>{children}</label>' , options : optionsChildrenAllowed } ,
91
91
{ code : '<label htmlFor="children">{children}</label>' , options : optionsChildrenAllowed } ,
92
+ { code : '<label htmlFor={id}>{ labelText }<div><input id={id} type="checkbox" name={id} value={value} /></div></label>' , options : optionsRequiredEvery } ,
93
+ { code : '<label htmlFor={id}>{ labelText }<div><div><div><div><input id={id} type="checkbox" name={id} value={value} /></div></div></div></div></label>' , options : optionsRequiredEvery } ,
92
94
] . map ( parserOptionsMapper ) ,
93
95
invalid : [
94
96
// DEFAULT ELEMENT 'label' TESTS
95
- { code : '<label id="foo" />' , errors : [ expectedEveryError ] } ,
96
- { code : '<label htmlFor={undefined} />' , errors : [ expectedEveryError ] } ,
97
- { code : '<label htmlFor={`${undefined}`} />' , errors : [ expectedEveryError ] } ,
98
- { code : '<label>First Name</label>' , errors : [ expectedEveryError ] } ,
99
- { code : '<label {...props}>Foo</label>' , errors : [ expectedEveryError ] } ,
100
- { code : '<label><input /></label>' , errors : [ expectedEveryError ] } ,
101
- { code : '<label>{children}</label>' , errors : [ expectedEveryError ] } ,
102
- { code : '<label htmlFor="foo" />' , errors : [ expectedEveryError ] } ,
103
- { code : '<label htmlFor={"foo"} />' , errors : [ expectedEveryError ] } ,
104
- { code : '<label htmlFor={foo} />' , errors : [ expectedEveryError ] } ,
105
- { code : '<label htmlFor={`${id}`} />' , errors : [ expectedEveryError ] } ,
106
- { code : '<label htmlFor="foo">Test!</label>' , errors : [ expectedEveryError ] } ,
97
+ { code : '<label id="foo" />' , errors : [ expectedEveryError ] , options : optionsRequiredEvery } ,
98
+ { code : '<label htmlFor={undefined} />' , errors : [ expectedEveryError ] , options : optionsRequiredEvery } ,
99
+ { code : '<label htmlFor={`${undefined}`} />' , errors : [ expectedEveryError ] , options : optionsRequiredEvery } ,
100
+ { code : '<label>First Name</label>' , errors : [ expectedEveryError ] , options : optionsRequiredEvery } ,
101
+ { code : '<label {...props}>Foo</label>' , errors : [ expectedEveryError ] , options : optionsRequiredEvery } ,
102
+ { code : '<label><input /></label>' , errors : [ expectedEveryError ] , options : optionsRequiredEvery } ,
103
+ { code : '<label>{children}</label>' , errors : [ expectedEveryError ] , options : optionsRequiredEvery } ,
104
+ { code : '<label htmlFor="foo" />' , errors : [ expectedEveryError ] , options : optionsRequiredEvery } ,
105
+ { code : '<label htmlFor={"foo"} />' , errors : [ expectedEveryError ] , options : optionsRequiredEvery } ,
106
+ { code : '<label htmlFor={foo} />' , errors : [ expectedEveryError ] , options : optionsRequiredEvery } ,
107
+ { code : '<label htmlFor={`${id}`} />' , errors : [ expectedEveryError ] , options : optionsRequiredEvery } ,
108
+ { code : '<label htmlFor="foo">Test!</label>' , errors : [ expectedEveryError ] , options : optionsRequiredEvery } ,
109
+ { code : '<label htmlFor={id}>{ labelText }<div><div><div><div><div id={id} type="checkbox" name={id} value={value} /></div></div></div></div></label>' , errors : [ expectedEveryError ] , options : optionsRequiredEvery } ,
107
110
//
108
111
// // CUSTOM ELEMENT ARRAY OPTION TESTS
109
- { code : '<Label></Label>' , errors : [ expectedEveryError ] , options : array } ,
110
- { code : '<Label htmlFor="foo" />' , errors : [ expectedEveryError ] , options : array } ,
111
- { code : '<Label htmlFor={"foo"} />' , errors : [ expectedEveryError ] , options : array } ,
112
- { code : '<Label htmlFor={foo} />' , errors : [ expectedEveryError ] , options : array } ,
113
- { code : '<Label htmlFor={`${id}`} />' , errors : [ expectedEveryError ] , options : array } ,
114
- { code : '<Label htmlFor="foo">Test!</Label>' , errors : [ expectedEveryError ] , options : array } ,
115
- { code : '<Descriptor htmlFor="foo" />' , errors : [ expectedEveryError ] , options : array } ,
116
- { code : '<Descriptor htmlFor={"foo"} />' , errors : [ expectedEveryError ] , options : array } ,
117
- { code : '<Descriptor htmlFor={foo} />' , errors : [ expectedEveryError ] , options : array } ,
118
- { code : '<Descriptor htmlFor={`${id}`} />' , errors : [ expectedEveryError ] , options : array } ,
112
+ {
113
+ code : '<Label></Label>' ,
114
+ errors : [ expectedEveryError ] ,
115
+ options : optionsComponents ,
116
+ } ,
117
+ {
118
+ code : '<Label htmlFor="foo" />' ,
119
+ errors : [ expectedEveryError ] ,
120
+ options : [ { ...optionsComponents [ 0 ] , ...optionsRequiredEvery [ 0 ] } ] ,
121
+ } ,
122
+ {
123
+ code : '<Label htmlFor={"foo"} />' ,
124
+ errors : [ expectedEveryError ] ,
125
+ options : [ { ...optionsComponents [ 0 ] , ...optionsRequiredEvery [ 0 ] } ] ,
126
+ } ,
127
+ {
128
+ code : '<Label htmlFor={foo} />' ,
129
+ errors : [ expectedEveryError ] ,
130
+ options : [ { ...optionsComponents [ 0 ] , ...optionsRequiredEvery [ 0 ] } ] ,
131
+ } ,
132
+ {
133
+ code : '<Label htmlFor={`${id}`} />' ,
134
+ errors : [ expectedEveryError ] ,
135
+ options : [ { ...optionsComponents [ 0 ] , ...optionsRequiredEvery [ 0 ] } ] ,
136
+ } ,
137
+ {
138
+ code : '<Label htmlFor="foo">Test!</Label>' ,
139
+ errors : [ expectedEveryError ] ,
140
+ options : [ { ...optionsComponents [ 0 ] , ...optionsRequiredEvery [ 0 ] } ] ,
141
+ } ,
142
+ {
143
+ code : '<Descriptor htmlFor="foo" />' ,
144
+ errors : [ expectedEveryError ] ,
145
+ options : [ { ...optionsComponents [ 0 ] , ...optionsRequiredEvery [ 0 ] } ] ,
146
+ } ,
147
+ {
148
+ code : '<Descriptor htmlFor={"foo"} />' ,
149
+ errors : [ expectedEveryError ] ,
150
+ options : [ { ...optionsComponents [ 0 ] , ...optionsRequiredEvery [ 0 ] } ] ,
151
+ } ,
152
+ {
153
+ code : '<Descriptor htmlFor={foo} />' ,
154
+ errors : [ expectedEveryError ] ,
155
+ options : [ { ...optionsComponents [ 0 ] , ...optionsRequiredEvery [ 0 ] } ] ,
156
+ } ,
157
+ {
158
+ code : '<Descriptor htmlFor={`${id}`} />' ,
159
+ errors : [ expectedEveryError ] ,
160
+ options : [ { ...optionsComponents [ 0 ] , ...optionsRequiredEvery [ 0 ] } ] ,
161
+ } ,
119
162
{
120
163
code : '<Descriptor htmlFor="foo">Test!</Descriptor>' ,
121
164
errors : [ expectedEveryError ] ,
122
- options : array ,
165
+ options : [ { ... optionsComponents [ 0 ] , ... optionsRequiredEvery [ 0 ] } ] ,
123
166
} ,
124
- { code : '<Label id="foo" />' , errors : [ expectedEveryError ] , options : array } ,
167
+ { code : '<Label id="foo" />' , errors : [ expectedEveryError ] , options : optionsComponents } ,
125
168
{
126
169
code : '<Label htmlFor={undefined} />' ,
127
170
errors : [ expectedEveryError ] ,
128
- options : array ,
171
+ options : optionsComponents ,
129
172
} ,
130
173
{
131
174
code : '<Label htmlFor={`${undefined}`} />' ,
132
175
errors : [ expectedEveryError ] ,
133
- options : array ,
176
+ options : optionsComponents ,
134
177
} ,
135
- { code : '<Label>First Name</Label>' , errors : [ expectedEveryError ] , options : array } ,
178
+ { code : '<Label>First Name</Label>' , errors : [ expectedEveryError ] , options : optionsComponents } ,
136
179
{
137
180
code : '<Label {...props}>Foo</Label>' ,
138
181
errors : [ expectedEveryError ] ,
139
- options : array ,
182
+ options : optionsComponents ,
140
183
} ,
141
- { code : '<Descriptor id="foo" />' , errors : [ expectedEveryError ] , options : array } ,
184
+ { code : '<Descriptor id="foo" />' , errors : [ expectedEveryError ] , options : optionsComponents } ,
142
185
{
143
186
code : '<Descriptor htmlFor={undefined} />' ,
144
187
errors : [ expectedEveryError ] ,
145
- options : array ,
188
+ options : optionsComponents ,
146
189
} ,
147
190
{
148
191
code : '<Descriptor htmlFor={`${undefined}`} />' ,
149
192
errors : [ expectedEveryError ] ,
150
- options : array ,
193
+ options : optionsComponents ,
151
194
} ,
152
195
{
153
196
code : '<Descriptor>First Name</Descriptor>' ,
154
197
errors : [ expectedEveryError ] ,
155
- options : array ,
198
+ options : optionsComponents ,
156
199
} ,
157
200
{
158
201
code : '<Descriptor {...props}>Foo</Descriptor>' ,
159
202
errors : [ expectedEveryError ] ,
160
- options : array ,
203
+ options : optionsComponents ,
161
204
} ,
162
- { code : '<label>{children}</label>' , errors : [ expectedEveryError ] , options : array } ,
205
+ { code : '<label>{children}</label>' , errors : [ expectedEveryError ] , options : optionsComponents } ,
163
206
{ code : '<label htmlFor="foo" />' , errors : [ expectedNestingError ] , options : optionsRequiredNesting } ,
164
207
{ code : '<label>First Name</label>' , errors : [ expectedNestingError ] , options : optionsRequiredNesting } ,
165
208
{ code : '<label>First Name</label>' , errors : [ expectedSomeError ] , options : optionsRequiredSome } ,
0 commit comments