emulate key in browser
Tries to emulate browser reaction for special keys like tab, arrows or backspace.
This helps testing behavior of components in unit tests (e.g. with jasmine or jest) without the need to launch a test enviroment and real browser (e.g. webdriver). Be aware that this sould not replace your real browser tests, but it will simplify early behavior tests.
Interactive demo: https://emulate-key-in-browser.net-root.de
npm i emulate-key-in-browser
- selection in multiline inputs
- line navigation will use character count, not character offset width and position like browsers
- there are environmen specific behaviors when hitting the cursor with arrow down or up key. (see emulate-shift-arrows-spec for details)
- tab to elements with scrollbars
Firefox selects elements that are not selectable as soon as they get scrollbars (overflow: auto) - not decided yet how to handle that. Current behavior is to ignore them.
There are automated tests for emulating keys in Chrome and Firefox. There are also automated tests that check the behavior of Chrome is equal (except multi line arrow key selection) to the emulated behavior. There's more information in our TESTING_CONCEPT.md.