If you're coming to Elixir from another language, you might wonder how to assert that a process sent a message to another process.
The key is to remember that each test itself is also an Erlang process (and has its own pid).
We can send a message to the test process's mailbox, and then use `assert_receive` to assert we got the message.
When you want to assert that a process sends a message, you just need to make sure the process is sending the messages back to the test's pid.
We do this by creating a stub that forwards messages.
Say you have GenServer process that handles Payroll. Each time an employee is registered with the process, it sends a notification using GenEvent.
You want to assert that the event is sent.
This is what your Payroll server looks like:
It can be used like this:
To test it, we'll need to create a stub GenEvent handler to forward messages back to the test:
And that is all folks..