Functions for simulating events on DOM nodes and React components.
If you're looking to implement your own custom action, this example shows how to do it.
Note on the operating DOM container:
When these helpers are called directly, they will operate with the "root node" as the DOM container. However, the recommended approach is to use them via Scope objects that you receive through drilling, in which case the container is whatever the scope is representing at the time.
Invoking through the Scope API
import drill from 'react-drill'
drill(component)
.find('.something')
.click()
Invoking a helper directly based on rootNode
const drill = require('react-drill');
drill.Selectors.setRootNode(document.body);
drill.Actions.find('.something');
// => document.body.querySelector('.something');
Simulate blur on any HTMLElement.
Simulate a change on any HTMLElement.
selector | String | HTMLElement |
attrs | Object The "change" event attributes. |
Check a checkbox.
This action dispatches a native browser event as well as the React change event.
Simulate a React mouse-click on any HTMLElement.
selector | String | HTMLElement |
options | Object Synthetic event options to pass to React. |
Simulate a native browser mouse-click event on any HTMLElement.
Dispatch a Native event using dispatchEvent to trigger events added via
addEventListener
.
This is useful if you need to interface with a non-React library.
selector | String | HTMLElement |
type | String |
attrs | Object |
Fill a text widget with some text.
This action modifies the DOM node's "value" property and triggers the React "input" and "change" events.
Simulate focus on any HTMLElement.
Simulate single "keyDown" event. Useful to test an isolated[1] onKeyDown
handler.
[1] See the note on Actions.keyPress
Simulate single "keyPress" event. Useful to test an isolated[1] onKeyPress
handler.
[1] When a user is performing an action that triggers such an event in the browser, it will be preceded and followed by other events. For this reason, this action is not a reliable simulation for such a scenario. Consider using Actions.fillIn or Actions.typeIn instead.
Simulate single "keyUp" event. Useful to test an isolated[1] onKeyUp
handler.
[1] See the note on Actions.keyPress
Simulate a mouse-down on any HTMLElement.
TODO: accept a button?
Simulate a mouseEnter on any HTMLElement. Assumes you are leaving
document.body
; use Actions.mouseTransition if you need to control both targets
Simulate a mouseLeave on any HTMLElement. Assumes you are entering
document.body
; use Actions.mouseTransition if you need to control both
targets.
Simulate a mouseEnter + mouseLeave events for two nodes
Both the native mouseOut and mouseOver events need to be simulated in order for the mouseEnter or mouseLeave to fire.
Simulate a mouse-up on any HTMLElement.
TODO: accept a button?
Paste some textual content into some text widget triggering the React "paste" event.
References:
Select an option inside a <select /> tag.
selector | String | HTMLElement |
value | String The value of the <option /> you want to select. |
Submit a form elment.
Simulate key-presses to fill in an <input /> with some text.
Unmark a checkbox as checked.
This action dispatches a native browser event as well as the React change event.