Module

Elmish.Test.Events

Package
purescript-elmish-testing-library
Repository
collegevine/purescript-elmish-testing-library

#change Source

change :: forall m. Testable m => String -> m Unit

A convenience specialization of fireEvent, simulating the change event with the given value.

find "input" >> change "some text"

#click Source

click :: forall m. Testable m => m Unit

A convenience specialization of fireEvent, simulating the click event.

find "button" >> click

#clickOn Source

clickOn :: forall m. Testable m => String -> m Unit

A convenience function, finding an element by CSS selector and simulating the click event on it.

clickOn "button.t--my-button"

#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.