Skip to content

Commit bc62cfb

Browse files
authored
Lazy create accessible dom elements (#79)
* Query for specific buttons when doing accessibility tests to prevent issues with leaky Graphics instances
1 parent 8fc4f85 commit bc62cfb

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

test/accessibility.test.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ describe('Keyboard navigation', () => {
1313
const t = new Thing();
1414
g.add(t);
1515
simulateEvent('keydown', { key: 'Tab' }, document.querySelector('#game'));
16-
const button = document.querySelector('button');
16+
const button = document.getElementById(
17+
HIDDEN_KEYBOARD_NAVIGATION_DOM_ELEMENT_ID(t._id)
18+
);
1719
expect(button).not.toBeNull();
1820
button.dispatchEvent(new Event('focus'));
1921
expect(button.textContent).toEqual(t.describe());
@@ -23,7 +25,9 @@ describe('Keyboard navigation', () => {
2325
const t = new Thing();
2426
g.add(t);
2527
simulateEvent('keydown', { key: 'Tab' }, document.querySelector('#game'));
26-
const button = document.querySelector('button');
28+
const button = document.getElementById(
29+
HIDDEN_KEYBOARD_NAVIGATION_DOM_ELEMENT_ID(t._id)
30+
);
2731
expect(button.style.cssText.replace(/\s+/g, '')).toEqual(
2832
KEYBOARD_NAVIGATION_DOM_ELEMENT_STYLE.replace(/\s+/g, '')
2933
);
@@ -32,8 +36,10 @@ describe('Keyboard navigation', () => {
3236
const g = new Graphics();
3337
const t = new Thing();
3438
g.add(t);
35-
simulateEvent('keydown', { key: 'Tab' }, document.querySelector('#game'));
36-
const button = document.querySelector('button');
39+
simulateEvent('keydown', { key: 'Tab' }, window);
40+
const button = document.getElementById(
41+
HIDDEN_KEYBOARD_NAVIGATION_DOM_ELEMENT_ID(t._id)
42+
);
3743
expect(button.style.cssText.replace(/\s+/g, '')).toEqual(
3844
KEYBOARD_NAVIGATION_DOM_ELEMENT_STYLE.replace(/\s+/g, '')
3945
);

0 commit comments

Comments
 (0)