跳到主要内容

测试通知

测试会话通知

要检查是否通过会话发送了通知,请使用 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.'),
);