Skip to content

Commit d549cb2

Browse files
authored
Add test for validating aria properties for accessibility_requirements (#2329)
* fix aria mapping * remove comment * add test for aria properties * remove title and only * remove title and only * remove title and only * add one more property * update test * remove only
1 parent 32fe6af commit d549cb2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

__tests__/frontmatter.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,22 @@ function validateRuleFrontmatter({ frontmatter }, metaData) {
9393
/**
9494
* The below check the `values` for every `key - value` pair of accessibility requirements
9595
*/
96-
const accRequirementValues = Object.values(accessibility_requirements)
97-
test.each(accRequirementValues)('has expected keys for accessibility requirement: `%p`', accReq => {
98-
expect(accReq).not.toBeNull()
99-
expect(typeof accReq).toBe('object')
100-
const keys = Object.keys(accReq).sort()
96+
const accessibilityReqs = Object.entries(accessibility_requirements).map(([key, value]) => ({ key, value }))
97+
test.each(accessibilityReqs)('has expected keys for accessibility requirement: `%p`', ({ key, value }) => {
98+
expect(value).not.toBeNull()
99+
expect(typeof value).toBe('object')
100+
const keys = Object.keys(value).sort()
101101

102102
if (keys.includes('secondary')) {
103103
expect(keys.length).toBe(1)
104-
expect(typeof accReq.secondary).toBe('string')
104+
expect(typeof value.secondary).toBe('string')
105105
} else {
106+
const requiredProps = ['failed', 'forConformance', 'inapplicable', 'passed']
107+
if (!/wcag-technique:.*/.test(key) && !/wcag2\d:.*/.test(key)) {
108+
requiredProps.push('title')
109+
}
106110
expect(keys.length).toBeGreaterThanOrEqual(4)
107-
expect(keys).toIncludeAllMembers(['failed', 'forConformance', 'inapplicable', 'passed'])
111+
expect(keys).toIncludeAllMembers(requiredProps)
108112
}
109113
})
110114
}

0 commit comments

Comments
 (0)