repeater field test

please assist, am trying to check if a field in the repeater can through error if not available, and how i can use file in pest test to fill the field for testing. Here is a rough idea of what am trying to do. The class class Add extends Component implements HasForms { use InteractsWithForms; public $name = ''; public $phone_number = ''; protected function getFormSchema(): array { return [ TextInput::make('name') ->label('Full name') ->required(), Repeater::make('phones') ->relationship() ->schema([ TextInput::make('phone_number') ->label('Phone Number') ->hint('E.g: 255713001001 or 0713001001') ->required(), ]) ->label('Phone numbers') ->defaultItems(1) ->minItems(1) ->createItemButtonLabel('Add user phone number'), ]; } } The test livewire(Add::class) ->call('invite') ->assertHasErrors(['name', 'phone_number']);
3 Replies
LeandroFerreira
livewire(Add::class)
->fillForm([
'name' => fake()->firstName(),
'phones' => [
['phone_number' => fake()->phoneNumber()],
]
])
->call('invite')
->assertHasNoFormErrors();
livewire(Add::class)
->fillForm([
'name' => fake()->firstName(),
'phones' => [
['phone_number' => fake()->phoneNumber()],
]
])
->call('invite')
->assertHasNoFormErrors();
ngaiza_287
ngaiza_287OP2y ago
Thank you. And how do i check if there is an error?
LeandroFerreira
assertHasFormErrors
Want results from more Discord servers?
Add your server