View Source Kino.Test (Kino v0.14.0)
Conveniences for testing custom Kino components.
In practice, Kino.JS.Live
kinos communicate with Livebook via
the group leader. During tests, Livebook is out of the equation,
so we need to mimic this side of the communication. To do so, add
the following setup to your test module:
import Kino.Test
setup :configure_livebook_bridge
Summary
Functions
Asserts a Kino.JS.Live
kino will broadcast an event within
timeout
.
Asserts the given output is sent within timeout
.
Asserts the given output is sent directly to the given client within
timeout
.
Asserts the given output is sent directly to all clients within timeout
.
Asserts a Kino.JS.Live
kino will send an event within timeout
to the caller.
Asserts a smart cell update will be broadcasted within timeout
.
Connects to a Kino.JS.Live
kino and returns the initial data.
Sends a client event to a Kino.JS.Live
kino.
Starts a smart cell defined by the given module.
Functions
Asserts a Kino.JS.Live
kino will broadcast an event within
timeout
.
Examples
assert_broadcast_event(kino, "bump", %{by: 2})
Asserts the given output is sent within timeout
.
Examples
assert_output({:markdown, "_hey_"})
Asserts the given output is sent directly to the given client within
timeout
.
Examples
assert_output_to("client1", {:markdown, "_hey_"})
Asserts the given output is sent directly to all clients within timeout
.
Examples
assert_output_to("client1", {:markdown, "_hey_"})
Asserts a Kino.JS.Live
kino will send an event within timeout
to the caller.
Examples
assert_send_event(kino, "pong", %{})
assert_smart_cell_update(kino, attrs, source, timeout \\ 100)
View Source (macro)Asserts a smart cell update will be broadcasted within timeout
.
Matches against the source and attribute that are reported as part of the update.
If the source
argument is a string, that string is compared in an
exact match against the Kino's source.
Alternatively, the source
argument can be used to bind a variable
to the Kino's source, allowing for custom assertions against the
source.
Examples
assert_smart_cell_update(kino, %{"variable" => "x", "number" => 10}, "x = 10")
assert_smart_cell_update(kino, %{"variable" => "x", "number" => 10}, source)
assert source =~ "10"
Connects to a Kino.JS.Live
kino and returns the initial data.
If resolve_fun
is given, it runs after sending the connection
request and before awaiting for the reply.
Examples
data = connect(kino)
assert data == %{count: 1}
Sends a client event to a Kino.JS.Live
kino.
Examples
push_event(kino, "bump", %{"by" => 2})
Starts a smart cell defined by the given module.
Returns a Kino.JS.Live
kino for interacting with the cell, as
well as the initial source.
Examples
{kino, source} = start_smart_cell!(Kino.SmartCell.Custom, %{"key" => "value"})