jantinnerezo / livewire-alert

SweetAlert2 wrapper for Livewire
https://livewire-alert.jantinnerezo.com
MIT License
709 stars 73 forks source link

TypeError: Cannot read properties of undefined (reading 'component') #83

Closed jdjd1118 closed 2 years ago

jdjd1118 commented 2 years ago

See screenshot for error. This error occurs after a user clicks OK on an error alert $this->alert('error', 'Error message', [ 'toast' => false, 'showConfirmationButton' => true ]);

image

jantinnerezo commented 2 years ago

Hello @jdjd1118

The error occurs when set showConfirmButton to true but you didn't set the event for the confirm button. I should add it to documentation, Thanks for submitting the issue.

jdjd1118 commented 2 years ago

@jantinnerezo Ah, I see. That makes sense. I set the event and no longer get that js error. One more question for you, due to this change our tests no longer pass because of the event array in the payload. Previously it was just an empty array but now it has the component ID in it. Any ideas on how to test that the correct alert was called with the correct message? Below is the assertion.

$this->assertDispatchedBrowserEvent('alert', [ 'type' => 'error', 'message' => $message, 'events' => [], 'options' => $options, 'data' => null ]);

jdjd1118 commented 2 years ago

@jantinnerezo Nevermind, I figured it out. This is what I have now: $this->assertDispatchedBrowserEvent('alert', [ 'type' => 'error', 'message' => $message, 'events' => [ 'onConfirmed' => [ 'id' => $this->id, 'component' => 'self', 'listener' => 'confirmed' ] ], 'options' => $options, 'data' => null ]);