Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Feb 14, 2024
1 parent 9ce3454 commit 59425b8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/menu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ test('adds menu navigation', () => {

press(window, 'ArrowUp')
equal(window.document.activeElement, items[2])

press(window, 'ArrowDown')
equal(window.document.activeElement, items[0])
})

test('stops tacking on loosing focus', () => {
Expand Down Expand Up @@ -151,3 +154,31 @@ test('stops event tracking', () => {
press(window, 'ArrowDown')
equal(window.document.activeElement, items[1])
})

test('ignores broken DOM', () => {
let window = new JSDOM().window
startKeyUX(window, [menuKeyUX()])

window.document.body.innerHTML =
'<a href="#" role="menuitem">Home</a>' +
'<a href="#" role="menuitem">About</a>' +
'<a href="#" role="menuitem">Contact</a>'
let items = window.document.querySelectorAll('a')
items[0].focus()

press(window, 'ArrowDown')
equal(window.document.activeElement, items[0])

window.document.body.innerHTML =
'<nav role="menu">' +
'<a href="#" role="menuitem">Home</a>' +
'<a href="#" role="menuitem">About</a>' +
'<a href="#" role="menuitem">Contact</a>' +
'</nav>'
let another = window.document.querySelectorAll('a')
another[0].focus()

window.document.querySelector('nav')!.role = ''
press(window, 'ArrowDown')
equal(window.document.activeElement, another[0])
})

0 comments on commit 59425b8

Please sign in to comment.