Testing Laravel Mail view

Posted 4 months ago by longestdrive


I can now successfully test that a mail is sent using Mail::fake() using a test like this:

       Mail::assertSent(Contact::class, function ($mail) use ($request) {

            return $mail->subject == "Website Contact";

But this doesn't appear to extend to testing that the view is rendered correctly.

I know I can view a mailable using :


I can use that to check it renders correctly but I want to be able to do this within my phpunit test.

For example running the above test on a mail passess as long as I have called Mail::fake() but Iif I then remove that call and rerun the test (and remove the fake assertions` the test fails with errors if I haven't passed the correct data over.

So how I can correctly test the email view is rendered correctly and sent in a test using Mail::fake()?


Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.