LiveIsolatedComponent (live_isolated_component v0.3.1)
Functions for testing LiveView stateful components in isolation easily.
Link to this section Summary
Functions
Asserts that a given handle event has been received.
Asserts the return value of a handle_event
Asserts that a given handle_info event has been received.
Updates the assigns of the component.
Updates the key in assigns of the component.
Renders the given component in isolation and live so you can tested like you would test any LiveView.
Link to this section Functions
Asserts that a given handle event has been received.
Depending on the number of parameters, different parts are checked:
- With no parameters, just that a handle_event message has been received.
- With one parameter, just the event name is checked.
- With two parameters, both event name and the parameters are checked.
- The optional last argument is the timeout, defaults to 100 milliseconds
If you just want to check the parameters without checking the event name,
pass nil
as the event name.
Asserts the return value of a handle_event
Asserts that a given handle_info event has been received.
If only the view is passed, only that a handle_info is received is checked. With an optional event name, we check that too. The third argument is an optional timeout, defaults to 100 milliseconds.
live_assign(view, keyword_or_map)
Updates the assigns of the component.
{:ok, view, _html} = live_isolated_component(SomeComponent, assigns: %{description: "blue"})
live_assign(view, %{description: "red"})
live_assign(view, key, value)
Updates the key in assigns of the component.
{:ok, view, _html} = live_isolated_component(SomeComponent, assigns: %{description: "blue"})
live_assign(view, :description, "red")
Renders the given component in isolation and live so you can tested like you would test any LiveView.
It accepts the following options:
:assigns
accepts a map of assigns for the component.:handle_event
accepts a handler for thehandle_event
callback in the LiveView.:handle_info
accepts a handler for thehandle_info
callback in the LiveView.:slots
accepts different slot descriptors.