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
App.Settingsdoesn’t call any function, just get a value from your Application config store.App.BoundSettingsdoesn’t implement the behaviour.UnexpectedCallErrorusually 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.
0
Last Post!
newelixiruser
Popular in Questions
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
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
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
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
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
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
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
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...
New
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
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
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
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...
New
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...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









