Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir 是什么导致Phoenix 1.5.4在控制器测试期间不发出json?_Elixir_Phoenix Framework - Fatal编程技术网

Elixir 是什么导致Phoenix 1.5.4在控制器测试期间不发出json?

Elixir 是什么导致Phoenix 1.5.4在控制器测试期间不发出json?,elixir,phoenix-framework,Elixir,Phoenix Framework,下面是我收到的错误/堆栈跟踪: ** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for {:safe, ["<!DOCTYPE html>\...</html>\n"]} of type Tuple, Jason.Encoder protocol must always be explicitly implemented. This protocol is i

下面是我收到的错误/堆栈跟踪:

   ** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for {:safe, ["<!DOCTYPE html>\...</html>\n"]} of type Tuple, Jason.Encoder protocol must always be explicitly implemented. This protocol is implemented for the following type(s): Ecto.Association.NotLoaded, Ecto.Schema.Metadata, MixAudit.Advisory, MixAudit.Vulnerability, MixAudit.Report, MixAudit.Dependency, Date, BitString, Jason.Fragment, Any, Map, NaiveDateTime, List, Integer, Time, DateTime, Decimal, Atom, Float
     code: |> post("/api/v1/horses", Jason.encode!(params))
     stacktrace:
       (jason 1.2.1) lib/jason.ex:199: Jason.encode_to_iodata!/2
       (phoenix 1.5.4) lib/phoenix/controller.ex:776: Phoenix.Controller.render_and_send/4
       (phoenix 1.5.4) lib/phoenix/endpoint/render_errors.ex:78: Phoenix.Endpoint.RenderErrors.instrument_render_and_send/5
       (phoenix 1.5.4) lib/phoenix/endpoint/render_errors.ex:64: Phoenix.Endpoint.RenderErrors.__catch__/5
       (phoenix 1.5.4) lib/phoenix/test/conn_test.ex:225: Phoenix.ConnTest.dispatch/5
       test/my_app_web/controllers/api/v1/horses_controller_test.exs:100: (test)

令人费解的是,“post”指的是一个json端点——路由器通过一个“api”管道,该管道具有
插件(:accepts,[“json”])
——这组测试中的其他测试似乎没有这个问题。我一直在进行基本的调试(注释代码行、执行IO.puts等),但我似乎仍然无法找出失败的地方。你知道是什么原因造成的,或者有没有更好的调试方法?其他控制器测试似乎也可以,所以我正在调查这些问题,但这个问题目前没有任何意义。

这看起来像是在发生运行时错误或找不到端点时收到的调试错误。查看收到的html以了解更多信息。谢谢,我最终弄明白了-我们使用Mox的方式是一种奇怪的模拟,如果我没有提供正确的模拟函数调用次数,它会引发错误。
params = %{
    "animals" => ["horses"],
    "type" => "mammal",
    "user" => %{
      "id" => "1",
      "email" => "greg@gmail.com"
    }
}