A mocking library for Elixir that uses the Erlang meck library to provide module mocking functionality for tests.
Mock is a mocking library for the Elixir programming language that enables developers to create mock modules for testing purposes. It leverages the Erlang meck library and provides convenient Elixir macros to integrate mocking functionality seamlessly into test suites, allowing developers to isolate and test code with external dependencies.
Elixir developers writing unit and integration tests who need to mock external dependencies like HTTP clients, databases, or third-party APIs. It is particularly useful for developers working on test suites that require controlled environments to verify interactions with external modules.
Developers choose Mock because it offers a clean, Elixir-native interface to the underlying Erlang meck library, making it easier to write and maintain tests with mocks. Its macros like `with_mock` and `test_with_mock` simplify test setup, and features like partial mocking with `:passthrough` and advanced assertion helpers provide flexibility and clarity in test code.
Mocking library for Elixir language
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Offers Elixir-native macros like `with_mock` and `test_with_mock` that integrate seamlessly into ExUnit tests, simplifying mock setup and improving code readability as shown in the README examples.
Provides a range of assertion macros such as `assert_called` with wildcard and pattern matching support via `:meck.is/1`, enabling precise verification of function calls without manual checks.
Includes the `:passthrough` option to mock specific functions while allowing access to other functions in the module, useful for isolating dependencies without full module replacement.
Allows defining mock functions with multiple clauses to return different values based on input patterns, making it easy to simulate varied responses from external services.
Cannot mock functions called internally within the same module without refactoring to use fully qualified names, a limitation explicitly admitted in the README's 'NOT SUPPORTED' section.
Mocking modules cannot be done asynchronously, requiring tests to run with `async: false`, which slows down test suites and limits parallelism in larger projects.
Does not support mocking macros directly, forcing developers to create wrapper functions as a workaround, adding unnecessary complexity and boilerplate to tests.