要检查通知是否已通过会话发送,使用 assertNotified() 辅助函数:
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();
});您可以选择性地传递一个通知标题以进行测试:
use Filament\Notifications\Notification;
use function Pest\Livewire\livewire;
it('sends a notification', function () {
livewire(CreatePost::class)
->assertNotified('Unable to create post');
});或者测试是否已发送确切的通知:
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.'),
);
});相反地,你可以断言某个通知未发送:
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.'),
);