mockth
Gleam modules mocking library. This is simple wrapper around Erlang meck library.
gleam add mockth
Usage
It provides a simple API to mock Gleam modules and functions. All you need to use mockth.expect
function to mock any external function with your own implementation.
import gleeunit
import gleeunit/should
import gleam/function
import mockth
pub fn main() {
gleeunit.main()
}
pub fn expect1_test() {
let assert Ok(_) =
mockth.expect1("gleam/function", "identity", fn(_args) { "hello" })
mockth.validate("gleam/function")
|> should.equal(True)
mockth.mocked()
|> should.equal(["gleam/function"])
function.identity("world")
|> should.equal("hello")
mockth.unload_all()
}
Don’t forget to unload all mocks after each test case.
Further documentation can be found at https://hexdocs.pm/mockth.
Development
gleam run # Run the project
gleam test # Run the tests
gleam shell # Run an Erlang shell