Testing LiveView and Presence: How to simulate a user has left (e.g. closed tab)

To simulate a user being unauthenticated and disconnected in all liveviews and channels you can do:

MyAppWeb.Endpoint.broadcast("users_socket:#{user.id}", "disconnect", %{})

This covered in the documentation here Disconnecting all instances of a live user.