测试

所有本指南内的示例都会使用 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');
});

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

需要帮助? 加入论坛 或者打开 GitHub讨论

喜欢Filament?

Filament 中文文档由 laravel-filament.cn 翻译整理。站长用爱发电,希望为英文阅读不畅的朋友提供快速掌握Filament框架的途径。文档的翻译,社区的运营维护都需要时间精力上的付出。如果文档社区使你受益,如果你想支持站长...

打赏