dom-sim ·
dom-sim allows you to simulate user interaction with your interface by firing DOM events and changing input values.
Installation
npm install --save-dev dom-sim
Usage
Simulating events
You can simulate DOM events by using trigger()
.
triggerbutton, 'click'
Additionally you can optionally pass an object with properties to be added to the event object.
triggerinput, 'keydown',
Setting inputs element values
setTextInputValuedocument.querySelector"input[type=text]", "Sasquatch" //Text field now has value "Sasquatch"setTextAreaValuedocument.querySelector"textarea", "Sasquatch" //Text area now has value "Sasquatch"setCheckboxValuedocument.querySelector"input[type=check]", true //Checkbox is now checkedsetRadioButtondocument.querySelector"input[type=radio]", true //Radio button is now selectedsetSelectValuedocument.querySelector"select", "Hancock" //Dropdown list now has the value "Hancock" selected
Don't forget to fire the appropriate event after you change an input value or any code watching for changes will be unaware of the change.
setTextInputValueinput, "Sasquatch"triggerinput, 'change'