EventEmitter (wallaby v0.28.0) View Source
This module offers telemetry style event emission for testing purposes.
If you'd like to emit a message to the event stream, you can call emit/1
from your implementation code. This is macro, and will not result in any AST injection when not being compiled in the test env.
defmodule ImplMod do
use EventEmitter, :emitter
def implementation do
# some logic
emit %{name: :implementation, module: __MODULE__, metadata: %{unique_identifier: some_variable}}
end
end
If you'd like to await on a message emitted by implementation code, you can call await/3
from your test code after registering a handler for your test process
defmodule TestMod do
use EventEmitter, :receiver
test "some test" do
EventEmitter.add_handler(self())
# some tricky asynchronous code
await :implementation, __MODULE__, %{unique_identifier: some_variable}
end
end
You can use EventEmitter by starting it in your test helper.
# test_helper.exs
EventEmitter.start_link([])
ExUnit.start()
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.