Laravel - Mail - Testing Mailables
Laravel provides several convenient methods for testing that your mailables contain the content that you expect. These methods are: assertSeeInHtml
, assertDontSeeInHtml
, assertSeeInText
, and assertDontSeeInText
.
As you might expect, the "HTML" assertions assert that the HTML version of your mailable contains a given string, while the "text" assertions assert that the plain-text version of your mailable contains a given string:
use App\Mail\InvoicePaid;
use App\Models\User;
public function test_mailable_content()
{
$user = User::factory()->create();
$mailable = new InvoicePaid($user);
$mailable->assertSeeInHtml($user->email);
$mailable->assertSeeInHtml('Invoice Paid');
$mailable->assertSeeInText($user->email);
$mailable->assertSeeInText('Invoice Paid');
}