Skip to content

Commit

Permalink
[Tests] label-has-associated-control: add additional test cases
Browse files Browse the repository at this point in the history
- Add test cases for non-nested labels with custom controlComponents
- Fix small typo in mayContainChildComponent util
- See jsx-eslint#962
  • Loading branch information
lb- authored and ljharb committed Oct 22, 2024
1 parent d92446c commit 30d2318
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions __tests__/src/rules/label-has-associated-control-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const nestingValid = [
{ code: '<label>foo<progress /></label>' },
{ code: '<label>foo<textarea /></label>' },
// Custom controlComponents.
{ code: '<label>A label<CustomInput /></label>', options: [{ controlComponents: ['CustomInput'] }] },
{ code: '<label><span>A label<CustomInput /></span></label>', options: [{ controlComponents: ['CustomInput'] }] },
{ code: '<label><span>A label<CustomInput /></span></label>', settings: componentsSettings },
{ code: '<CustomLabel><span>A label<CustomInput /></span></CustomLabel>', options: [{ controlComponents: ['CustomInput'], labelComponents: ['CustomLabel'] }] },
Expand Down Expand Up @@ -141,6 +142,7 @@ const nestingInvalid = [
{ code: '<label><span><span><span><span aria-label="A label" /><input /></span></span></span></label>', options: [{ depth: 5 }], errors: [expectedError] },
{ code: '<label><span><span><span><input aria-label="A label" /></span></span></span></label>', options: [{ depth: 5 }], errors: [expectedError] },
// Custom controlComponents.
{ code: '<label>A label<OtherCustomInput /></label>', options: [{ controlComponents: ['CustomInput'] }], errors: [expectedError] },
{ code: '<label><span>A label<CustomInput /></span></label>', options: [{ controlComponents: ['CustomInput'] }], errors: [expectedError] },
{ code: '<CustomLabel><span>A label<CustomInput /></span></CustomLabel>', options: [{ controlComponents: ['CustomInput'], labelComponents: ['CustomLabel'] }], errors: [expectedError] },
{ code: '<CustomLabel><span label="A label"><CustomInput /></span></CustomLabel>', options: [{ controlComponents: ['CustomInput'], labelComponents: ['CustomLabel'], labelAttributes: ['label'] }], errors: [expectedError] },
Expand Down
2 changes: 1 addition & 1 deletion src/util/mayContainChildComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function mayContainChildComponent(
if (childNode.type === 'JSXExpressionContainer') {
return true;
}
// Check for comonents with the provided name.
// Check for components with the provided name.
if (
childNode.type === 'JSXElement'
&& childNode.openingElement
Expand Down

0 comments on commit 30d2318

Please sign in to comment.