Skip to content

Add test for validating aria properties for accessibility_requirements #2329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 26, 2025
Merged
18 changes: 11 additions & 7 deletions __tests__/frontmatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,22 @@ function validateRuleFrontmatter({ frontmatter }, metaData) {
/**
* The below check the `values` for every `key - value` pair of accessibility requirements
*/
const accRequirementValues = Object.values(accessibility_requirements)
test.each(accRequirementValues)('has expected keys for accessibility requirement: `%p`', accReq => {
expect(accReq).not.toBeNull()
expect(typeof accReq).toBe('object')
const keys = Object.keys(accReq).sort()
const accessibilityReqs = Object.entries(accessibility_requirements).map(([key, value]) => ({ key, value }))
test.each(accessibilityReqs)('has expected keys for accessibility requirement: `%p`', ({ key, value }) => {
expect(value).not.toBeNull()
expect(typeof value).toBe('object')
const keys = Object.keys(value).sort()

if (keys.includes('secondary')) {
expect(keys.length).toBe(1)
expect(typeof accReq.secondary).toBe('string')
expect(typeof value.secondary).toBe('string')
} else {
const requiredProps = ['failed', 'forConformance', 'inapplicable', 'passed']
if (!/wcag-technique:.*/.test(key) && !/wcag2\d:.*/.test(key)) {
requiredProps.push('title')
}
expect(keys.length).toBeGreaterThanOrEqual(4)
expect(keys).toIncludeAllMembers(['failed', 'forConformance', 'inapplicable', 'passed'])
expect(keys).toIncludeAllMembers(requiredProps)
}
})
}
Expand Down