how to test anonymous actions?

As per title, how do I test anonymous actions?
4 Replies
oddvalue
oddvalue10mo ago
@Davide did you ever find a solution to this?
awcodes
awcodes10mo ago
Anonymous actions are still just registered form component actions. You should be able to call them the same way in the test. ->callFormComponentAction(‘action_name’)
Izzy
Izzy10mo ago
It doesn't seem to work... Too few arguments to function Livewire\Features\SupportTesting\Testable::Filament\Forms\Testing{closure}(), 1 passed in /Users/<username>/Code/Projects/website/vendor/laravel/framework/src/Illuminate/Macroable/Traits/Macroable.php on line 123 and at least 2 expected Could you please give me some advice? I'm stuck on this.
richardfila
richardfila9mo ago
I found the following code works for anonymous actions in an infolist. There are similar mount / call mounted functions for forms etc. Livewire::test(ViewUser::class, ['record' => $user->id]) ->call( 'mountInfolistAction', 'resendActivationEmail', '.resendActivationEmailAction', 'infolist', ) ->callMountedInfolistAction(); Where "resendActivationEmail" is the name of my anonymous action as defined in Action::make(). The next field with ".resendActivationEmailAction" is that same name prepended with a dot and appended with "Action". You can see all these values by inspecting the button element of the Action in the browser. On the Action used in the code shown I have requireConfirmation() set, so clicking the Action button opens a modal. Therefore the second call in the test callMountedInfolistAction() is required to call the modal and effectively submit the empty form it contains to act as pressing 'Yes' to the confirmation.
Want results from more Discord servers?
Add your server