How to test PubSub Broadcasts?


I am doing my first baby steps with using Phoenix PubSub and added a call to broadcast to the context of my application model. Now I want to extend my test code to check the broadcasting of the message. So far, I found the assert_broadcast helper from Phoenix Channels, but nothing specific to Phoenix PubSub.

How do you test that your code pushes a message to PubSub? I checked various other posts in this forum, but I haven’t found a solution. Or, at least I haven’t understood, that it is the solution.

Best regards,

It was easier than I thought. Just discovered assert_receive and refute_received. I just had to call the code to subscribe to the PubSub topic in my testcode.

1 Like