write test for validating fields on the custom form component

I have a custom filament form component with two fields, prompt and SKU, I want to write a test suite for validating the form. Below is the test I have written to do the same but it says the component doesn't have errors it('will return validation notification submitting invalid data', function () { $component = livewire(MagentoForm::class) ->fillForm([ 'prompt' => 1, 'sku' => '' ]) ->assertHasFormErrors(['sku' => 'The sku field is required.']); });
5 Replies
LeandroFerreira
LeandroFerreira9mo ago
'sku' => null ?
Ajith Lal
Ajith LalOP9mo ago
Not working.
Ajith Lal
Ajith LalOP9mo ago
Yes. I did. The validation errors are not trapped since it is a custom livewire component.
Ajith Lal
Ajith LalOP9mo ago
For better clarity, I will explain what happened. I had to integrate a multi-form to a custom page. So I created a Livewire component https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component and set a form like below:
public function form(Form $form): Form
{
return $form
->schema([
Select::make('field1')
->options(...)
// ->native(false)
->required(),
TextInput::make('field2')
->required()
->minLength(3)
->maxLength(255),
])
->columns(3)
->statePath('customForm1');
}
public function form(Form $form): Form
{
return $form
->schema([
Select::make('field1')
->options(...)
// ->native(false)
->required(),
TextInput::make('field2')
->required()
->minLength(3)
->maxLength(255),
])
->columns(3)
->statePath('customForm1');
}
I have added 2 forms to the page https://filamentphp.com/docs/3.x/forms/adding-a-form-to-a-livewire-component#using-multiple-forms. When I write tests for validation messages, It says the form doesn't return any validation errors
Want results from more Discord servers?
Add your server