vendredi 29 janvier 2021

Use test helper function in controller test

I am getting the following error when I try to use a test helper function:

undefined function myfunction/0

the setup is as follows:

defmodule MyAppWeb.DashboardControllerTest do
  use MyAppWebWeb.ConnCase

  import TestHelpers

  describe "index" do
    setup [:myfunction] #<- This works perfectly
  
    test "some test", %{conn: conn} do
      conn = get(conn, "/")

      var = myfunction #<- This does not work
    end
  end
end

The test helper looks like this:

# File is located in "support/test_helpers.ex"

defmodule TestHelpers do

  def myfunction do
   #magic!
  end
end

It would be great if someone could elaborate! Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire