Skip to content

Testing component with Context #756

Open
@jpyamamoto

Description

@jpyamamoto

Hi,

I am trying to perform a test on a component that retrieves a value from the context and I can't find a proper way to achieve it.

Say I have the following Wrapper live component:

data items, :list, from_context: :navigation

def render(assigns) do
  ~F"""
    <div>
      <Navigation items={@items} />
    </div>
  """
end

I tried to pass the items through the use_config macro like this:

using_config Wrapper, items: [1, 2, 3] do
  html = render_surface do
    ~F"""
      <Wrapper id="navigation" />
    """
  end
end

but it throws a runtime error saying items is nil (not a valid list).

Is there a way to provide the render_surface with a context? Or perhaps to use something other than render_surface, say compile_surface (I tried that macro as well to no avail).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions