christophrumpel / missing-livewire-assertions

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

Cannot test for magic actions #26

Closed jonjakoblich closed 10 months ago

jonjakoblich commented 11 months ago

I ran into an issue trying to assert that a property was wired in my component, but via a magic action.

<a href="#" wire:click.prevent="$toggle('changeUser')">Change assigned user</a>

In my Livewire component changeUser is a property with a boolean value. I tried the following tests and both failed to match for a PCRE pattern.

Livewire::test(AssignUser::class,[
        'maintenanceRequest' => $maintenanceRequest,
    ])
        ->assertOk()
        ->assertMethodWired('$toggle(\'changeUser\')');
Livewire::test(AssignUser::class,[
        'maintenanceRequest' => $maintenanceRequest,
    ])
        ->assertOk()
        ->assertMethodWired(changeUser');

I think this could be accomplished by modifying the regular expression in the methods assertMethodWired and assertMethodNotWired to allow for magic actions.

christophrumpel commented 11 months ago

Hey, did not know about the magic methods. Good point. Would you be willing to creat a PR for that?

jonjakoblich commented 11 months ago

Yes, definitely willing! Before I work on that, what tool are you using to test/build your regular expressions? I kept getting an error with the tester I was using with your existing regex so just looking to be consistent with existing code.

christophrumpel commented 11 months ago

Hey, from what I remember, I did not write that regex 😅 The last few times I used AI to write it for me hehe. So if it can be improved, I'm open to that 👍