Skip to content

Commit 30d2318

Browse files
lb-ljharb
authored andcommitted
[Tests] label-has-associated-control: add additional test cases
- Add test cases for non-nested labels with custom controlComponents - Fix small typo in mayContainChildComponent util - See #962
1 parent d92446c commit 30d2318

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

__tests__/src/rules/label-has-associated-control-test.js

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const nestingValid = [
8686
{ code: '<label>foo<progress /></label>' },
8787
{ code: '<label>foo<textarea /></label>' },
8888
// Custom controlComponents.
89+
{ code: '<label>A label<CustomInput /></label>', options: [{ controlComponents: ['CustomInput'] }] },
8990
{ code: '<label><span>A label<CustomInput /></span></label>', options: [{ controlComponents: ['CustomInput'] }] },
9091
{ code: '<label><span>A label<CustomInput /></span></label>', settings: componentsSettings },
9192
{ code: '<CustomLabel><span>A label<CustomInput /></span></CustomLabel>', options: [{ controlComponents: ['CustomInput'], labelComponents: ['CustomLabel'] }] },
@@ -141,6 +142,7 @@ const nestingInvalid = [
141142
{ code: '<label><span><span><span><span aria-label="A label" /><input /></span></span></span></label>', options: [{ depth: 5 }], errors: [expectedError] },
142143
{ code: '<label><span><span><span><input aria-label="A label" /></span></span></span></label>', options: [{ depth: 5 }], errors: [expectedError] },
143144
// Custom controlComponents.
145+
{ code: '<label>A label<OtherCustomInput /></label>', options: [{ controlComponents: ['CustomInput'] }], errors: [expectedError] },
144146
{ code: '<label><span>A label<CustomInput /></span></label>', options: [{ controlComponents: ['CustomInput'] }], errors: [expectedError] },
145147
{ code: '<CustomLabel><span>A label<CustomInput /></span></CustomLabel>', options: [{ controlComponents: ['CustomInput'], labelComponents: ['CustomLabel'] }], errors: [expectedError] },
146148
{ code: '<CustomLabel><span label="A label"><CustomInput /></span></CustomLabel>', options: [{ controlComponents: ['CustomInput'], labelComponents: ['CustomLabel'], labelAttributes: ['label'] }], errors: [expectedError] },

src/util/mayContainChildComponent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default function mayContainChildComponent(
3535
if (childNode.type === 'JSXExpressionContainer') {
3636
return true;
3737
}
38-
// Check for comonents with the provided name.
38+
// Check for components with the provided name.
3939
if (
4040
childNode.type === 'JSXElement'
4141
&& childNode.openingElement

0 commit comments

Comments
 (0)