Phoenix.LiveViewTest.render_hook/3 does not allow a string value, whereas I can write a hook and liveview that sends and reads such datatype

Hi, there.

I have a hook that fetch select options on user input, and values are passed to an external js library.
This hook uses pushEvent(event, payload), where payload is a string, such as "bar".
unsigned_params received on facing liveview in handle_event/3 is the payload : "bar".

I can not use Phoenix.LiveViewTest.render_hook/3 to test this hook, as there is a guard clause on the value: is_map/1 or is_list/1.

So I can write hook and liveview that sends and receive a "bar" payload, but I can not write a test for it?

What do you think on the datatype of Phoenix.LiveView.handle_event/3? Could unsigned_params datatype be unioned with string and number?

Cheers!

handle_event is always passed a map of params. If a client is able to push a raw value, it is by accident and I’ll look into guarding against it within the LiveView.Channel. So update your client to use a map payload and you’re good to go!

2 Likes