View Source Kino.Test (Kino v0.8.1)

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

Link to this section Summary

Functions

Asserts a Kino.JS.Live kino will broadcast an event within timeout.

Asserts the given output is sent to 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.

Link to this section Functions

Link to this macro

assert_broadcast_event(kino, event, payload, timeout \\ 100)

View Source (macro)

Asserts a Kino.JS.Live kino will broadcast an event within timeout.

examples

Examples

assert_broadcast_event(kino, "bump", %{by: 2})
Link to this macro

assert_output(output, timeout \\ 100)

View Source (macro)

Asserts the given output is sent to within timeout.

examples

Examples

assert_output({:markdown, "_hey_"})
Link to this macro

assert_send_event(kino, event, payload, timeout \\ 100)

View Source (macro)

Asserts a Kino.JS.Live kino will send an event within timeout to the caller.

examples

Examples

assert_send_event(kino, "pong", %{})
Link to this macro

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

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"
Link to this function

configure_livebook_bridge(context)

View Source
Link to this function

connect(kino, resolve_fun \\ nil, timeout \\ 100)

View Source

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

Examples

data = connect(kino)
assert data == %{count: 1}
Link to this function

push_event(kino, event, payload)

View Source

Sends a client event to a Kino.JS.Live kino.

examples

Examples

push_event(kino, "bump", %{"by" => 2})
Link to this function

start_smart_cell!(module, attrs)

View Source

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

Examples

{kino, source} = start_smart_cell!(Kino.SmartCell.Custom, %{"key" => "value"})