Version

Theme

NOTE

You are currently viewing the documentation for Filament 4.x, which is currently in beta and is not stable. Breaking changes may be introduced to releases during the beta period. Please report any issues you encounter on GitHub.

Looking for the current stable version? Visit the 3.x documentation.

Testing

Testing notifications

Testing session notifications

To check if a notification was sent using the session, use the assertNotified() helper:

use function Pest\Livewire\livewire;

it('sends a notification', function () {
    livewire(CreatePost::class)
        ->assertNotified();
});
use Filament\Notifications\Notification;

it('sends a notification', function () {
    Notification::assertNotified();
});
use function Filament\Notifications\Testing\assertNotified;

it('sends a notification', function () {
    assertNotified();
});

You may optionally pass a notification title to test for:

use Filament\Notifications\Notification;
use function Pest\Livewire\livewire;

it('sends a notification', function () {
    livewire(CreatePost::class)
        ->assertNotified('Unable to create post');
});

Or test if the exact notification was sent:

use Filament\Notifications\Notification;
use function Pest\Livewire\livewire;

it('sends a notification', function () {
    livewire(CreatePost::class)
        ->assertNotified(
            Notification::make()
                ->danger()
                ->title('Unable to create post')
                ->body('Something went wrong.'),
        );
});

Conversely, you can assert that a notification was not sent:

use Filament\Notifications\Notification;
use function Pest\Livewire\livewire;

it('does not send a notification', function () {
    livewire(CreatePost::class)
        ->assertNotNotified()
        // or
        ->assertNotNotified('Unable to create post')
        // or
        ->assertNotNotified(
            Notification::make()
                ->danger()
                ->title('Unable to create post')
                ->body('Something went wrong.'),
        );
Edit on GitHub

Still need help? Join our Discord community or open a GitHub discussion

Previous
Testing actions