AF
Ash Frameworkโ€ข2mo ago
forest

Cinder Table and Testing

Thank you for Cinder. Very nice. I have some basic LiveView tests and they are now breaking with Cinder. I believe it is b/c the Table makes the query and the assert is happening before the data is loaded. What is the right fix for this in tests? I can add a timeout but that feels dirty.
elixir
test "lists all organizations", %{conn: conn, organization: organization} do
{:ok, index_live, html} = live(conn, ~p"/organizations")

assert html =~ "Listing Organizations"
assert html =~ organization.name
end
elixir
test "lists all organizations", %{conn: conn, organization: organization} do
{:ok, index_live, html} = live(conn, ~p"/organizations")

assert html =~ "Listing Organizations"
assert html =~ organization.name
end
This test fails with Cinder.
7 Replies
ZachDaniel
ZachDanielโ€ข2mo ago
@sevenseacat would be the one to say, but perhaps Cinder should look for Ash's disable_async? config and if set it should fetch results on page load and not do loading states? Or maybe have your own config for that to allow testing loading states etc.
sevenseacat
sevenseacatโ€ข2mo ago
internally we use render_async when testing, to wait for async data loading to happen before we run assertions
ZachDaniel
ZachDanielโ€ข2mo ago
oh interesting. Cool, didn't realize that was a thing ๐Ÿ™‚ (but makes perfect sense to exist in retrospect ๐Ÿ™‚
forest
forestOPโ€ข2mo ago
I didn't either. Nice. This works. Thanks.
test "lists all organizations", %{conn: conn, organization: organization} do
{:ok, index_live, html} = live(conn, ~p"/organizations")

assert html =~ "Listing Organizations"
assert html =~ "Loading..."
assert render_async(index_live) =~ organization.name
end
test "lists all organizations", %{conn: conn, organization: organization} do
{:ok, index_live, html} = live(conn, ~p"/organizations")

assert html =~ "Listing Organizations"
assert html =~ "Loading..."
assert render_async(index_live) =~ organization.name
end
I looked in the docs for testing notes, but didn't find anything. This might be a nice little testing tip to add.
ZachDaniel
ZachDanielโ€ข2mo ago
PR/issue would be great there ๐Ÿ™‚
forest
forestOPโ€ข2mo ago
will do it.
forest
forestOPโ€ข2mo ago
GitHub
Add docs for testing with render_async by forest ยท Pull Request #4...
Cinder uses assign_async to load data, so LiveView tests need to use render_async to wait for the data to load.

Did you find this page helpful?