© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•8mo ago•
5 replies
reppair

Testing modal form fields.

Given an action with a modal, with a form schema, I'd like to test that the form has specific fields. How is that done?

Example action
Action::make('export')
    ->label('Export Records')
    ->form([
        Select::make('export_format')
            ->label('Export Format')
            ->options([
                'csv' => 'CSV',
            ])
            ->required(),
    ])
    ->modalWidth('lg')
    ->modalSubmitActionLabel('Export')
    ->icon('heroicon-o-cloud-arrow-down')
    ->color('gray')
    ->link();
Action::make('export')
    ->label('Export Records')
    ->form([
        Select::make('export_format')
            ->label('Export Format')
            ->options([
                'csv' => 'CSV',
            ])
            ->required(),
    ])
    ->modalWidth('lg')
    ->modalSubmitActionLabel('Export')
    ->icon('heroicon-o-cloud-arrow-down')
    ->color('gray')
    ->link();


Example test
/** @test */
public function export_action_modal_has_select_field_for_format()
{
    Livewire::test(DomainActions::class, ['record' => $this->domain])
        ->mountAction('export')
        ->assertFormExists('form') // works
        ->assertFormFieldExists('export_format') // fails;
}
/** @test */
public function export_action_modal_has_select_field_for_format()
{
    Livewire::test(DomainActions::class, ['record' => $this->domain])
        ->mountAction('export')
        ->assertFormExists('form') // works
        ->assertFormFieldExists('export_format') // fails;
}


Fails with
Failed asserting that a field with the name [export_format] exists on the form with the name [form] on the [App\Filament\App\Resources\DomainResource\Widgets\DomainActions] component.
Failed asserting that null is an instance of class Filament\Forms\Components\Field.
Failed asserting that a field with the name [export_format] exists on the form with the name [form] on the [App\Filament\App\Resources\DomainResource\Widgets\DomainActions] component.
Failed asserting that null is an instance of class Filament\Forms\Components\Field.
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Testing modal form in resource relation
FilamentFFilament / ❓┊help
13mo ago
testing create data in modal form
FilamentFFilament / ❓┊help
3y ago
Testing create form modal on ManageResource page.
FilamentFFilament / ❓┊help
3y ago
Form Testing
FilamentFFilament / ❓┊help
2y ago