Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion that toast was called (with options?) #464

Open
nexxai opened this issue Nov 17, 2023 · 3 comments
Open

Assertion that toast was called (with options?) #464

nexxai opened this issue Nov 17, 2023 · 3 comments

Comments

@nexxai
Copy link

nexxai commented Nov 17, 2023

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

@usernotnull
Copy link
Owner

Hey.
You can easily be inspired from the tests in this library to make your own.

@nexxai
Copy link
Author

nexxai commented Nov 18, 2023

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', '[email protected]')
        ->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.

@usernotnull
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants