Open nexxai opened 9 months ago
Hey. You can easily be inspired from the tests in this library to make your own.
I've spent the last couple hours actually trying that, but I can't seem to figure out how to verify that if I call ->push();
while inside a Livewire component, how to verify that the Toast actually appeared.
Example code:
public function sendInvite(): void
{
...
toast()->success('Invite sent!')->push();
}
This test still fails:
test('a toast is pushed when invite is sent', function () {
assertFalse(ToastManager::componentRendered());
Livewire::test(Admin::class)
->set('emailAddress', 'bob@example.org')
->call('sendInvite');
assertTrue(ToastManager::componentRendered()); // <---- this line is what fails
});
I tried using the tests in this package as a guide to write my own but I can't even figure out the basic "does the component show", let alone is it a "success" type with the correct message.
All what you can test for is that your message is sent and exists in the session(). Anything beyond that is actually tested in this library, so would be redundant.
If you want to test that it is actually displayed on the front end, then you'd have to use a tool like Laravel Dusk, as the js part of this app cannot be tested without such tools.
I'm open to PRs if anyone is willing to write such tests or expand on the existing ones.
Description
Ok, so in my application, I'd like to be able to do something like
$this->assertToast(success, "Thanks for joining!");
to ensure that the toasts are actually being sent.Additional context
n/a