Module
Elmish.Test.Events
- Package
- purescript-elmish-testing-library
- Repository
- collegevine/purescript-elmish-testing-library
#fireEvent Source
fireEvent :: forall m r. Testable m => CanPassToJavaScript (Record r) => String -> Record r -> m Unit
Simulates a React-friendly event with the given name and given args, firing it on the current-context element. The second argument is a record of values that gets merged into the event object.
For example:
find "button" >> fireEvent "click" {}
find "input" >> fireEvent "change" { target: { value: "some text" } }
find "input" >> fireEvent "keyDown" { key: "Enter", keyCode: 13, which: 13 }
This function uses the Simulate
function from react-dom/test-utils
. See
https://reactjs.org/docs/test-utils.html#simulate
If the arguments record contains a field target
, which in turn contains a
field value
, the value of that field is assigned to the value
property
of the current-context element before firing the event. This special case
is intended to support events targeted at input fields, such as change
or
input
, where the event handler usually tries to access the
event.target.value
field.