Fiton012's avatar

Test a notification is shown that is outside of Livewire component

I have a module Product\Update that when is updated an event is dispatched using

        $this->dispatchBrowserEvent('notify', '`Product updated successfully.');

This event is send to the browser and a toaster notification is poped-up. The toaster notification is outside of the Product\Update component but in the html <body>.

As I checked the below code fails because it only checks the code inside the Livewire module while my toaster is outside of it.

Livewire::test(Product\Update::class)
            ->set('title', 'Mike')
            ->call('submitForm')
			->assertSee('Product updated successfully.');

How can I test this behavior?

0 likes
1 reply
tykus's avatar
tykus
Best Answer
Level 104

In the context of the Component test, you can assert that the Browser Event was dispatched:

Livewire::test(Product\Update::class)
            ->set('title', 'Mike')
            ->call('submitForm')
			->assertDispatchedBrowserEvent('notify');

You cannot see what happens outside the Component unit.

2 likes

Please or to participate in this conversation.