Test function was called exactly X times

If you are using OTP 21+ then you can write it as:

    @tag :wip
    test "calls given function X times" do
      counter = :counters.new(1, [])

      deps = [
        lookup_fn: fn _key ->
          :counters.add(counter, 1, 1)

          {:ok, 1}
        end
      ]

      MyApp.do_work(deps)
      assert 2 == :counters.get(counter, 1)
    end
1 Like