公告: 旧版文档请移步 -> http://v2.laravel-filament.cn/docs

Languages

Version

Theme

通知生成器

测试

所有本指南内的示例都会使用 Pest 编写。当然,你也可以使用 PHPUnit。

Session 通知

使用 assertNotified() 辅助函数,断言通知是否已经用 session 发送:

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.'),
);
});
Edit on GitHub

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