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

pejrich
I propose adding compact_map/2 to the Enum module. What is it? Sometimes you want to map over a collection, but sometimes you want to ma...
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
cheerfulstoic
I feel like Elixir is getting big enough and old enough that I’m starting to experience problems with conflicting dependencies. An examp...
New
nunobernardes99
On 1.8+, when we generate an authentication system with mix phx.gen.auth we can make use of magic link login which is amazing and a great...
New
Redbaritone
In the current Auth code, the email must change to be valid. This may be true for the two situations the author has in mind: Registering ...
New
andypearson
Hey all, I have been working on some performance improvements for the Phoenix application I work on. As part of this, through trial and...
New
woylie
We are seeing a lot of warning logs like this: navigate event to "https://someurl" failed because you are redirecting across live_sessio...
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54996 245
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

We're in Beta

About us Mission Statement