baezanat
Hello! I need to test that a Liveview broadcasts a message to a PubSub topic after a redirect. Anybody knows how I could go about testing whether a message is broadcasted? Thanks so much!
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










First Post!- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
CinderellaMan
Hello
I’m possibly misunderstanding the complexity but what I normally do is that I inject things like modules dynamically dependent on the environment. For example, the code which uses the
PubSubmodule to broadcast message to the topic, instead of the hardcodedPubSubmodule would have something like:and use it to broadcast:
Option 2:
You could subscribe to the topic to figure out have you received the expected message back.
Option 3:
The
broadcastfunction could be passed as an argumentI hope that helps somehow
Last Post!
baezanat
Thank you for your answer! So, the problem with option 2 is that the name of the topic is built with a unique session_id that I plugged into the session.
When I mount the liveview I store it into a socket assign and then retrieve it from there to broadcast a message. So in order to subscribe to the topic from my test, I would need to have the
session_idassigns, but I don’t think we can access the assigns in a test, right?To explain things better: my LV does something and, if successful, broadcasts a message to the topic (unique for each session) saying that the action was successful.
The message is then used by another LV, whose template is located in root, which issues a notification.
I want to test my initial LV, the one that does the action and then broadcasts a message. The problem is that, after the broadcast, there is a redirect, after which the LV is remounted. In my test, currently, I follow the redirect and then test for the html that the notifications LV in the root layout should insert upon receiving the message. But my test fails, presumably because right when the LV is mounted, the html isn’t yet included.
That last line fails, even though I correctly see the notification displayed… Presumably, as I said, because the redirect and the notification are asynchronous. So, I thought I should test just if my LV issues the message correctly before redirect, but I don’t know how to do it…
Another interesting thing about this case is that I had to add
:timer.sleep(10)just after the message is broadcasted and before the LV redirects (see code snipet again below); otherwise, the notification would not be displayed after the redirect.