@@ -19,11 +19,22 @@ import rule from '../../../src/rules/label-has-for';
19
19
20
20
const ruleTester = new RuleTester ( ) ;
21
21
22
- const expectedError = {
23
- message : 'Form label must have associated control' ,
22
+ const expectedNestingError = {
23
+ message : 'Form label must have the following type of associated control: nesting ' ,
24
24
type : 'JSXOpeningElement' ,
25
25
} ;
26
26
27
+ const expectedSomeError = {
28
+ message : 'Form label must have ANY of the following types of associated control: nesting, id' ,
29
+ type : 'JSXOpeningElement' ,
30
+ } ;
31
+
32
+ const expectedEveryError = {
33
+ message : 'Form label must have ALL of the following types of associated control: nesting, id' ,
34
+ type : 'JSXOpeningElement' ,
35
+ } ;
36
+
37
+
27
38
const array = [ {
28
39
components : [ 'Label' , 'Descriptor' ] ,
29
40
} ] ;
@@ -81,78 +92,78 @@ ruleTester.run('label-has-for', rule, {
81
92
] . map ( parserOptionsMapper ) ,
82
93
invalid : [
83
94
// DEFAULT ELEMENT 'label' TESTS
84
- { code : '<label id="foo" />' , errors : [ expectedError ] } ,
85
- { code : '<label htmlFor={undefined} />' , errors : [ expectedError ] } ,
86
- { code : '<label htmlFor={`${undefined}`} />' , errors : [ expectedError ] } ,
87
- { code : '<label>First Name</label>' , errors : [ expectedError ] } ,
88
- { code : '<label {...props}>Foo</label>' , errors : [ expectedError ] } ,
89
- { code : '<label><input /></label>' , errors : [ expectedError ] } ,
90
- { code : '<label>{children}</label>' , errors : [ expectedError ] } ,
91
- { code : '<label htmlFor="foo" />' , errors : [ expectedError ] } ,
92
- { code : '<label htmlFor={"foo"} />' , errors : [ expectedError ] } ,
93
- { code : '<label htmlFor={foo} />' , errors : [ expectedError ] } ,
94
- { code : '<label htmlFor={`${id}`} />' , errors : [ expectedError ] } ,
95
- { code : '<label htmlFor="foo">Test!</label>' , errors : [ expectedError ] } ,
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 ] } ,
96
107
//
97
108
// // CUSTOM ELEMENT ARRAY OPTION TESTS
98
- { code : '<Label></Label>' , errors : [ expectedError ] , options : array } ,
99
- { code : '<Label htmlFor="foo" />' , errors : [ expectedError ] , options : array } ,
100
- { code : '<Label htmlFor={"foo"} />' , errors : [ expectedError ] , options : array } ,
101
- { code : '<Label htmlFor={foo} />' , errors : [ expectedError ] , options : array } ,
102
- { code : '<Label htmlFor={`${id}`} />' , errors : [ expectedError ] , options : array } ,
103
- { code : '<Label htmlFor="foo">Test!</Label>' , errors : [ expectedError ] , options : array } ,
104
- { code : '<Descriptor htmlFor="foo" />' , errors : [ expectedError ] , options : array } ,
105
- { code : '<Descriptor htmlFor={"foo"} />' , errors : [ expectedError ] , options : array } ,
106
- { code : '<Descriptor htmlFor={foo} />' , errors : [ expectedError ] , options : array } ,
107
- { code : '<Descriptor htmlFor={`${id}`} />' , errors : [ expectedError ] , options : array } ,
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 } ,
108
119
{
109
120
code : '<Descriptor htmlFor="foo">Test!</Descriptor>' ,
110
- errors : [ expectedError ] ,
121
+ errors : [ expectedEveryError ] ,
111
122
options : array ,
112
123
} ,
113
- { code : '<Label id="foo" />' , errors : [ expectedError ] , options : array } ,
124
+ { code : '<Label id="foo" />' , errors : [ expectedEveryError ] , options : array } ,
114
125
{
115
126
code : '<Label htmlFor={undefined} />' ,
116
- errors : [ expectedError ] ,
127
+ errors : [ expectedEveryError ] ,
117
128
options : array ,
118
129
} ,
119
130
{
120
131
code : '<Label htmlFor={`${undefined}`} />' ,
121
- errors : [ expectedError ] ,
132
+ errors : [ expectedEveryError ] ,
122
133
options : array ,
123
134
} ,
124
- { code : '<Label>First Name</Label>' , errors : [ expectedError ] , options : array } ,
135
+ { code : '<Label>First Name</Label>' , errors : [ expectedEveryError ] , options : array } ,
125
136
{
126
137
code : '<Label {...props}>Foo</Label>' ,
127
- errors : [ expectedError ] ,
138
+ errors : [ expectedEveryError ] ,
128
139
options : array ,
129
140
} ,
130
- { code : '<Descriptor id="foo" />' , errors : [ expectedError ] , options : array } ,
141
+ { code : '<Descriptor id="foo" />' , errors : [ expectedEveryError ] , options : array } ,
131
142
{
132
143
code : '<Descriptor htmlFor={undefined} />' ,
133
- errors : [ expectedError ] ,
144
+ errors : [ expectedEveryError ] ,
134
145
options : array ,
135
146
} ,
136
147
{
137
148
code : '<Descriptor htmlFor={`${undefined}`} />' ,
138
- errors : [ expectedError ] ,
149
+ errors : [ expectedEveryError ] ,
139
150
options : array ,
140
151
} ,
141
152
{
142
153
code : '<Descriptor>First Name</Descriptor>' ,
143
- errors : [ expectedError ] ,
154
+ errors : [ expectedEveryError ] ,
144
155
options : array ,
145
156
} ,
146
157
{
147
158
code : '<Descriptor {...props}>Foo</Descriptor>' ,
148
- errors : [ expectedError ] ,
159
+ errors : [ expectedEveryError ] ,
149
160
options : array ,
150
161
} ,
151
- { code : '<label>{children}</label>' , errors : [ expectedError ] , options : array } ,
152
- { code : '<label htmlFor="foo" />' , errors : [ expectedError ] , options : optionsRequiredNesting } ,
153
- { code : '<label>First Name</label>' , errors : [ expectedError ] , options : optionsRequiredNesting } ,
154
- { code : '<label>First Name</label>' , errors : [ expectedError ] , options : optionsRequiredSome } ,
155
- { code : '<label>{children}</label>' , errors : [ expectedError ] , options : optionsRequiredSome } ,
156
- { code : '<label>{children}</label>' , errors : [ expectedError ] , options : optionsRequiredNesting } ,
162
+ { code : '<label>{children}</label>' , errors : [ expectedEveryError ] , options : array } ,
163
+ { code : '<label htmlFor="foo" />' , errors : [ expectedNestingError ] , options : optionsRequiredNesting } ,
164
+ { code : '<label>First Name</label>' , errors : [ expectedNestingError ] , options : optionsRequiredNesting } ,
165
+ { code : '<label>First Name</label>' , errors : [ expectedSomeError ] , options : optionsRequiredSome } ,
166
+ { code : '<label>{children}</label>' , errors : [ expectedSomeError ] , options : optionsRequiredSome } ,
167
+ { code : '<label>{children}</label>' , errors : [ expectedNestingError ] , options : optionsRequiredNesting } ,
157
168
] . map ( parserOptionsMapper ) ,
158
169
} ) ;
0 commit comments