In this episode, we're tackling a common frustration: how do you actually test that emails have been sent when you're using Laravel Dusk? Out of the box, Laravel's built-in mail faking doesn't really play nicely with Dusk, since Dusk runs tests in an actual browser and can't just intercept outgoing emails the way PHPUnit does.
So, we roll up our sleeves and start from the top—setting up a Laravel project (with Breeze for auth), making a simple form that sends an email when you hit a button, and getting Laravel Dusk installed and configured with its own testing environment (including a separate database and .env file for Dusk).
You'll see how we set our mailer up to "log" so emails end up in the log file—basically a hacky way to confirm something was sent (but not ideal). Pretty soon, though, you'll see why this is limited. That's when we introduce the laravel-dusk-fakes package, which gives us all the assertMailSent-style functionality we're used to, but inside Dusk!
We walk through how to install the package, set up Dusk to use it, and add the right traits and config so all your test emails and notifications get intercepted and stashed for easy assertions. You'll see exactly how to assert that the right email went to the right user with the right subject, and how to extend this for notifications as well.
By the end, you've got browser-based tests that can really check whether emails (and notifications) are going out, just like you'd expect with normal feature tests, with barely any more hassle. Super powerful, super handy, and you'll probably never want to write Dusk email tests any other way again.