Testing input filtering code in a text box requires a different approach than usual. While calling setValue
and triggering the change event works for most tests, this case demands testing the actual filtering process. This means simply calling setValue()
won't suffice.
Attempting to dispatch keydown
, keyup
, keypress
, and textinput
events revealed that the event handlers were being called but the text didn't display in the text box, except for Firefox where it partially worked. Different browsers may require different code implementations.
Example function and event dispatching code...
Despite the limitations imposed by web security measures, there are ways to enhance the testing environment such as launching Firefox with a specific profile or installing plugins tailored for the task at hand.
The aim is to steer clear of using Selenium and Java in JavaScript tests due to performance concerns and the potential duplication of DOM querying logic.
The ultimate question remains: How can one make the code actually modify the input? Are there settings adjustments or plugins that could be installed?
List of related questions:
- Link 1
- Link 2
- Link 3
- Link 4