Skip to content

Commit fd69512

Browse files
committed
Gracefully handle null annotations
closes instructure#7
1 parent b717e26 commit fd69512

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/a11y/renderScreenReaderHints.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ initEventHandlers();
1010
* @param {Array} annotations The annotations that hints are inserted for
1111
*/
1212
export default function renderScreenReaderHints(annotations) {
13+
annotations = Array.isArray(annotations) ? annotations : [];
14+
1315
// Insert hints for each type
1416
Object.keys(SORT_TYPES).forEach((type) => {
1517
let sortBy = SORT_TYPES[type];

test/a11y/renderScreenReaderHints.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ describe('a11y::renderScreenReaderHints', function () {
3232
});
3333

3434
describe('render', function () {
35+
it('should render without annotations', function () {
36+
let error;
37+
38+
try {
39+
renderScreenReaderHints();
40+
} catch (e) {
41+
error = e;
42+
}
43+
44+
equal(typeof error, 'undefined');
45+
});
46+
47+
it('should render with non-array annotations', function () {
48+
let error;
49+
50+
try {
51+
renderScreenReaderHints(null);
52+
} catch (e) {
53+
error = e;
54+
}
55+
56+
equal(typeof error, 'undefined');
57+
});
58+
3559
it('should render highlight', function () {
3660
renderScreenReaderHints([{
3761
type: 'highlight',

0 commit comments

Comments
 (0)