newelixiruser

newelixiruser

Mox return a UnexpectedCallError

Hi,
I’m trying to test my config settings.
To do that, i use a module that load them: like this

defmodule App.SettingsBehaviour do
  @moduledoc """
  Define the behavior for accessing environment variable settings
  """
  @callback is_search_enabled :: boolean
end

defmodule App.BoundSettings do
  @options Application.get_env(:app, :options, App.Settings)

  def is_search_enabled do
    @options.is_search_enabled
  end
end

defmodule App.Settings do
  @behaviour App.SettingsBehaviour

  @impl App.SettingsBehaviour
  def is_search_enabled, do: Application.get_env(:app, :search_enabled, false)
end

config/test.exs

config :app, :options, App.OptionsMock
config :app, search_enabled: true

I have a liveview controller calling App.Settings, and when i try to mock it it returns UnexpectedCallError. Does anyone understand what could fail here?

Marked As Solved

cevado

cevado

  • App.Settings doesn’t call any function, just get a value from your Application config store.
  • App.BoundSettings doesn’t implement the behaviour.
  • UnexpectedCallError usually means that you’re calling the the mock module without setting any expectation on it.

given the context you provided, code paths that use AppBoundSettings doesn’t have a expectation on App.OptionsMock.

Last Post!

newelixiruser

newelixiruser

One of the expectation was missing making load of tests fails

Where Next?

Popular in Questions Top

PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130579 1222
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49134 226
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40082 209
New

We're in Beta

About us Mission Statement