Testing surface components

Can anyone give me an example of how to test a surface component. I currently have this:

defmodule DoomWeb.Components.CardTest do
  use Surface.LiveViewTest

  import Phoenix.LiveViewTest

  alias DoomWeb.Components.Card

  test "creates a <Card> with title and description" do
    html =
      render_surface do
        <Card />

    assert html =~ """

and the only thing I get is:

== Compilation error in file test/doom_web/components/card_test.exs ==
** (CompileError) test/doom_web/components/card_test.exs:8: undefined function test/2 (there is no such import)
    (elixir 1.13.4) lib/kernel/parallel_compiler.ex:455: Kernel.ParallelCompiler.require_file/2
    (elixir 1.13.4) lib/kernel/parallel_compiler.ex:348: anonymous fn/5 in Kernel.ParallelCompiler.spawn_workers/7

The there is no test/2 ??? Where is that suposte to come from?

1 Like

I think it should be:

  use ExUnit.Case
  use Surface.LiveViewTest

  alias DoomWeb.Components.Card


Still have a problem… dont know why the render is carring about comparing whitepaces, but is another 3 month talk.