Fires DOM events on elements inside a JSDom-mounted LiveView, mirroring
dom-testing-library's
fireEvent.<eventName> API.
Event names are extracted at compile time directly from the installed
@testing-library/dom package (via a short Node invocation), so the list
stays in sync automatically with whichever version is in priv/node_modules.
Usage
import Phoenix.LiveViewTest, only: [element: 2, element: 3]
alias PhoenixTestJsdom.FireEvent
view
|> FireEvent.mouse_down(element(view, "button#menu"))
|> FireEvent.key_down(element(view, "input"), %{key: "Enter", code: "Enter"})
|> FireEvent.change(element(view, "input[name=email]"), %{target: %{value: "a@b.com"}})
|> PhoenixTestJsdom.render()The third argument merges on top of the event's defaultInit. The special
key :target (a map) is applied as element property assignments before
dispatch, which is how RTL's change(el, { target: { value: "x" } }) works.
All functions return the view for pipeability. Use PhoenixTestJsdom.render/1
afterwards to see the updated HTML.
For custom or non-standard events, use the generic fire/4:
FireEvent.fire(view, element(view, "#my-el"), "my-custom-event", %{detail: 42})Attribution
Event names and defaults are taken from dom-testing-library (MIT License, Copyright (c) 2018 Kent C. Dodds).
Summary
Functions
Fires an arbitrary named DOM event on the resolved element.
Functions
Fires an arbitrary named DOM event on the resolved element.
Useful for custom events or any event not in dom-testing-library's event map.