Skip to content

Commit

Permalink
Fixed #10 where if a tagName is being checked for reserved in the DOM…
Browse files Browse the repository at this point in the history
… object but does not exist in the DOM object an exception was being thrown
  • Loading branch information
Erin Doyle committed Apr 18, 2017
1 parent 3cb951f commit 3173a1d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"env": {
"browser": true,
"node": true,
"es6": true
"es6": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 2017,
Expand All @@ -17,6 +18,7 @@
],
"plugins": [
"babel",
"mocha",
"react"
],
"rules": {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"eslint-plugin-babel": "^3.1.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^3.0.2",
"eslint-plugin-mocha": "^4.9.0",
"eslint-plugin-react": "^6.10.3",
"karma": "^0.13.22",
"karma-chrome-launcher": "^0.1.7",
Expand Down
9 changes: 6 additions & 3 deletions src/rules/no-unsupported-elements-use-aria.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default [{
msg: 'This element does not support ARIA roles, states and properties.',
AX: 'AX_ARIA_12',
test(tagName, props) {
const reserved = DOM[tagName].reserved || false;
const reserved = (Object.prototype.hasOwnProperty.call(DOM, tagName) && DOM[tagName].reserved) || false;
const prop = hasProp(props, Object.keys(aria).concat('role'));

return !reserved || !prop;
Expand All @@ -30,9 +30,12 @@ export const fail = [{
}];

export const pass = [{
when: 'the reserver element is not given an illegal prop',
when: 'the reserved element is not given an illegal prop',
render: React => <meta charSet="UTF-8" />
}, {
when: 'an illegal props is given to a non-reserved elemeent',
when: 'an illegal prop is given to a non-reserved element',
render: React => <div aria-hidden />
}, {
when: 'an illegal prop is given to an unknown element',
render: React => <g aria-hidden />
}];
9 changes: 8 additions & 1 deletion src/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ export default class Suite {
}

// perform the test
const pass = await test(tagName, props, children, ctx);
let pass;
// try/catch so that exceptions are not silently swallowed by await
try {
pass = await test(tagName, props, children, ctx);
} catch (error) {
console.log(error);
pass = false;
}

if (!pass) {
done({
Expand Down

0 comments on commit 3173a1d

Please sign in to comment.