Here you go for Pest tests:
How do I test Flux::toast ?
I know Flux is very new, but maybe this is more a Livewire question than a Flux one.
I have a Livewire component with a form. The submit method is something like the following
public function submit(): ?Redirector
{
$this->validate();
if ($this->everythingIsOk()) {
// Save the data
redirect()->route('home');
}
Flux::toast(
heading: 'Error!',
text: 'Sorry try again.',
variant: 'danger'
);
return null;
}
I can easily test the validation, and the happy path. Now I want to test if everything else is not OK (the everythingIsOk() is not a real method, I've just put it there to show the logic) and therefore the toast message appears.
Since Flux::toast is another Livewire component I don't know how to do it.
I know I could probably refactor it so my component emit an event and the event listener show the toast, but is this really the only way? It's such a simple component that it feels like an overkill to use events.
Please or to participate in this conversation.