Testing Laravel Mail view

Posted 4 months ago by longestdrive

Hi

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) {
            $mail->build();

            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 :

Route::get('\mailable`)

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()?

Thanks

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

Reply to

Use Markdown with GitHub-flavored code blocks.