Languages

Version

Theme

测试

测试通知

测试 Session 通知

要测试通知是否使用 Session 发送,请使用 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.'),
        );
})
Edit on GitHub

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

Previous
测试 Action