SkillAgentSearch skills...

Mok

Function mock generator for Elixir

Install / Use

/learn @jechol/Mok
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

mix test Hex version badge License badge

mok is small library to inject and mock functions easily.

Installation

The package can be installed by adding mok to your list of dependencies in mix.exs:

def deps do
  [{:mok, "~> 0.1"}]
end

Usage

inject, mock


  defmodule Target do
    require Mok

    def call(mocks) do
      a = [1, 2, 3] |> List.first() |> Mok.inject(mocks, "unmatched") # 1 (not injected)
      b = [1, 2, 3] |> List.first() |> Mok.inject(mocks, "matched") # 10 (injected)
      c = [1, 2, 3] |> List.first() |> Mok.inject(mocks, nil) # 1 (not injected)
      d = [1, 2, 3] |> List.first() |> Mok.inject(mocks) # 100 (injected)

      a + b + c + d
    end
  end
require Mok

assert 4 == Target.call(%{})

assert 112 ==
          Target.call(
            Mok.mock(%{
              {&List.first/1, "matched"} => 10,
              &List.first/1 => 100
            })
          )

License

This project is licensed under the MIT License - see the LICENSE file for details

Related Skills

View on GitHub
GitHub Stars9
CategoryDevelopment
Updated8mo ago
Forks0

Languages

Elixir

Security Score

62/100

Audited on Aug 2, 2025

No findings