microsoft / tabster

Web Application Keyboard Navigation Tools
https://tabster.io
MIT License
121 stars 36 forks source link

Verifying components relying on tabster through unit tests #280

Open sjwilczynski opened 1 year ago

sjwilczynski commented 1 year ago

Hey folks,

I am using Fluent 9 Popover and wanted to verify that correct element is focused open opening the Popover. For the component I created, I can visually verify in Storybook that correct element is focused. However, when I want to make such assertion in unit tests, it seems to no longer be the case. Can tabster functionality be somehow verified in jest and jsdom environment? Or the only way to verify is to have e2e tests, rendering browser window?

ling1726 commented 1 year ago

Unfortunately the browser is the only way to assert what happens with focus correctly in general, we've generally tried to avoid asserting anything focus related in JSDOM. Tabster and other focus utilities have a habit of doing things asynchronously with timeouts in some cases, so it's not an easy proposition to test focus there