christophrumpel / missing-livewire-assertions

Adding the missing Livewire assertions to your Laravel project
MIT License
136 stars 25 forks source link

Can't assert methods which are attached to actions other than `click` #22

Closed dalbo closed 7 months ago

dalbo commented 1 year ago

It would be great to be able to assert methods which are wired to actions other than click. I will often attach a method to a change event on a select dropdown, as follows.

<select wire:change="setValue($event.target.value)">
    <option value='1'>Value 1</option>
    <option value='2'>Value 2</option>
</select>

Two thoughts on how this could be implemented

christophrumpel commented 1 year ago

Hey, nice idea.

What about being specific like assertMethodWiredToClick and assertMethodWiredToChange?

@nuernbergerA what do you think?

dalbo commented 1 year ago

So my concern with making specific assertions like that is that you will end up with dozens of them. I want change but someone else wants keyup and someone else wants mouseover etc. It would certainly work, but may become somewhat overwhelming with so many potential options.

christophrumpel commented 1 year ago

Good point. Do you know how many there are? That might help to decide.

dalbo commented 1 year ago

From the documentation it can be any browser event (and possibly any custom event too)

https://livewire.laravel.com/docs/actions#event-listeners

Event listeners
Livewire supports a variety of event listeners, allowing you to respond to various types of user interactions:

wire:click | Triggered when an element is clicked
wire:submit | Triggered when a form is submitted
wire:keydown | Triggered when a key is pressed down
wire:mouseenter | Triggered when the mouse enters an element
wire:* | Whatever text follows wire: will be used as the event name of the listener

Because the event name after wire: can be anything, Livewire supports any browser event you might need to listen for. For example, to listen for transitionend, you can use wire:transitionend.
christophrumpel commented 1 year ago

Ok I see. Then lets keep the dedicated click method and add a generic method like you suggested. Would you want to work an a PR for that?

dalbo commented 1 year ago

Sure, will see what I can do.