© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•16mo ago
Kane G

Is it possible to test broadcast notifications?

I'm currently using reverb to broadcast notifications, everything is working fine and the notifications are coming through. I'd like to run some tests to ensure this is always the case but I can't seem to get
assertNotified
assertNotified
to return
true
true
while using
toBroadcast()
toBroadcast()
. If I switch it back to
send()
send()
the notification test passes (which a few other small changes - eg. removing notification from
notify()
notify()
function.)

I'm triggering the notification like this:

try {
    if (Carbon::parse($this->data['starts_at'])->gte(Carbon::parse($this->data['ends_at']))) {
        throw new \Exception('Date Error');
    }
} catch (\Exception $e) {
    auth()->user()->notify(
        Notification::make()
            ->danger()
            ->title('Date Error')
            ->body('Ends at date should be greater than the starts at date.')
            ->persistent()
            ->toBroadcast()
    );

    $this->halt();
}
try {
    if (Carbon::parse($this->data['starts_at'])->gte(Carbon::parse($this->data['ends_at']))) {
        throw new \Exception('Date Error');
    }
} catch (\Exception $e) {
    auth()->user()->notify(
        Notification::make()
            ->danger()
            ->title('Date Error')
            ->body('Ends at date should be greater than the starts at date.')
            ->persistent()
            ->toBroadcast()
    );

    $this->halt();
}


Testing notification like this:
Livewire::actingAs($this->user)
    ->test(CreateTenancy::class)
    ->fillForm([
        'starts_at' => now()->addDays(5)->toDateString(),
        'ends_at' => now()->toDateString(),
    ])
    ->call('create')
    ->assertNotified(
        Notification::make()
            ->danger()
            ->title('Date Error')
            ->body('Ends at date should be greater than the starts at date.')
            ->persistent()
    );
Livewire::actingAs($this->user)
    ->test(CreateTenancy::class)
    ->fillForm([
        'starts_at' => now()->addDays(5)->toDateString(),
        'ends_at' => now()->toDateString(),
    ])
    ->call('create')
    ->assertNotified(
        Notification::make()
            ->danger()
            ->title('Date Error')
            ->body('Ends at date should be greater than the starts at date.')
            ->persistent()
    );


Test currently fails with:
A notification was not sent
Failed asserting that null is not null.
A notification was not sent
Failed asserting that null is not null.


Thanks.
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Broadcast Pusher Notifications
FilamentFFilament / ❓┊help
3y ago
Broadcast & database notifications failed
FilamentFFilament / ❓┊help
3y ago
Is it possible to custom the database notifications modal ?
FilamentFFilament / ❓┊help
3y ago
Is it possible to test forms in actions?
FilamentFFilament / ❓┊help
14mo ago