Testing component with Context

Open
#756 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
elixir
Domain
backend, testing

Research direction

Start with the Wrapper component's from_context: :navigation declaration and the render_surface and compile_surface calls shown in the issue. Determine how context should be supplied during component tests, then verify that rendering Wrapper with navigation items no longer produces a nil-list error.

Written by the indexing model from the issue text.

Description

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).

Dominant language
Elixir
Stars
2.1k
Forks
146
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from surface-ui/surface

All issues in surface-ui/surface

Similar issues

More Elixir issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.