Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Assert flash for Laracasts/flash
namespace Tests;
trait CanAssertFlash
protected function assertFlash($level, $message, $important = false, $title = null, $overlay = false)
$expectedNotification = [
'title' => $title,
'message' => $message,
'level' => $level,
'important' => $important,
'overlay' => $overlay
$flashNotifications = json_decode(json_encode(session('flash_notification')), true);
if (! $flashNotifications) {
$this->fail('Failed asserting that a flash message was sent.');
"Failed asserting that the flash message '$message' is present."
namespace Tests\Feature\FlashTest;
use Tests\TestCase;
use Tests\CanAssertFlash;
class FlashTest extends TestCase
use RefreshDatabase;
use CanAssertFlash;
/** @test */
public function a_flash_message_was_sent()
$this->assertFlash('success', "Thank you! We'll get back to you in 24 hours.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment