begedin

begedin

What is your minimum test setup for a stateful component?

I’m trying to write a library which provides a complex phoenix live component the the app dependant on it.

As part of that, I’m also trying to test it, but it’s looking like being able to test the component in a deeper way is a tad complicated.

I effectively have to

  • setup a full phoenix application, with an endpoint
  • setup a view which renders the component and fully delegates all component interaction onto it’s own state
  • setup a route for that view if I render using live, or use live_isolated
  • interact with and assert on the view itself, rather than the component

It works, but I’m wondering if anyone figured out anything simpler. Is there anything on the roadmap to simplify it?

It would even be useful to have just a conversation about it.

Most Liked

eksperimental

eksperimental

I am sure if this could be useful, maybe you can use this as a starting point.
https://github.com/eksperimental/lean_phoenix_server

you will have to add LiveView

begedin

begedin

Wont have time to check until the next weekend, but it looks like it might be. Thank you for this.

petemcfarlane

petemcfarlane

I wanted to do this today. In my test I defined a TestView module, which had a minimal render() function, then I passed this to live_isolated() as a second parameter.
This worked quite well, but it was awkward to test that handle_event calls were bubbling up to the parent view, I also had to define a minimal handle_event function in the TestView, which assigned some properties to the socket, and then had a conditional in my render function to return a completely different view.

I wonder if we could create a live_component_in_view function or something that just takes the stateful component, and add some other assertion for assert_handle_event("event", params)?

Last Post!

begedin

begedin

That would be my ideal scenario. I was going to look into it this weekend and try and figure it out. That + some way to ship css and js easily with the component, as a library, would really allow for an easier time with portable 3rd party components.

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
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
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
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
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement