Rubas

Rubas

Enhancing LiveViewTest API for better async testing

Current Challenge

When testing LiveViews that use assign_async, we can’t really operate on the async data.

  • render_async(view) waits for async operations but only returns the html

  • All the other render_* test functions (render_click, render_patch, etc.) can not be used in combination with async content

Problem

  • We can’t use render_patch and then assert on async data that loads after navigation
  • We can’t use render_click on elements that appear in async-loaded content

Solution

I’m not sure yet what the most elegant way to solve this is …

Marked As Solved

LostKobrakai

LostKobrakai

What’s the problem with just returning HTML? The LV test api is not a functional API. view includes a pid, which is what most apis talk to, so you don’t need to get a new view back everywhere.

Last Post!

Rubas

Rubas

You are right. I missed something here.

This works

      # Navigate to appointments list
      {:ok, view, _html} = live(conn, ~q"/:locale/user/appointments")

      # Navigate to first appointment
      render_patch(view, ~q"/:locale/user/appointments/123")

      # Wait for async data to load and render
      html1 = render_async(view)

      # Verify first appointment data
      assert html1 =~ "Location One"
      assert html1 =~ "123-456"
      assert html1 =~ "John Doe"

      # Navigate directly to second appointment
      render_patch(view, ~q"/:locale/user/appointments/456")

      # Wait for async data to load and render
      html2 = render_async(view)

      # Verify second appointment data
      assert html2 =~ "Location Two"
      assert html2 =~ "789-012"
      assert html2 =~ "Jane Smith"

      # Ensure first appointment data is no longer present
      refute html2 =~ "Location One"

Where Next?

Popular in Proposals: Ideas Top

cevado
IEx is a very powerfull shell and it would be awesome to have all this power integrated inside a code editor. Clojure enables something l...
New
Flo0807
Hello everyone! Phoenix LiveView v0.18 introduced the special attributes :let, :for and :if. In addition to the :if special attribute, I...
New
dogweather
Hi Phoenix community! First off, huge thanks for an amazing framework - Phoenix has been a joy to work with. I have a small UX suggestio...
New
aglassman
Problem The cancel_async function is easily overlooked. Since the results of “outdated” tasks are ignored, it’s easy for developers to a...
New
GenericJam
I’ve been messing around with image generation models recently and thought this could be wrapped in a library or people could just use th...
New
engineeringdept
In 2026 double submit/session tokens are no longer necessary to prevent against CSRF attacks. Instead, we can use the Sec-Fetch-Site head...
New
pierrelegall
Problem Currently, List.first/2 and List.last/2 return a default value (or nil) when the list is empty. However, there are cases where an...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement