test "test1" do
assigns = %{}
name="abcd"
component_string =
rendered_to_string(~H"""
<Web.Components.component1 name={name} />
""")
# assertions here
end
the test itself works fine, but i get a warning saying the following
Using variables in HEEx templates are discouraged as they disable change tracking. You are only allowed to access variables defined by Elixir control-flow structures, such as if/case/for, or those defined by the special attributes :let/:if/ ....
this is because i’m accessing the name variable. i can of course inline this, but i have made it simple in this case, in my actual project this is a more complex object.
ssign/3 expects a socket from Phoenix.LiveView/Phoenix.LiveComponent or an assigns map from Phoenix.Component as first argument, got: %{}You passed an assigns map that does not have the relevant change tracking information. This typically means you are calling a function component by hand instead of using the HEEx template syntax. If you are using HEEx, make sure you are calling a component using:
The APIs for modifing assigns only work with the change tracked structs you get from liveview. If you’re using a plain map you can just edit it like any other map. You won’t need change tracking in tests anyways.