Select getSearchResultsUsing , Test read null
This is my code
protected function getFormSchema(): array
{
//TODO SISTEMARE CODICE DUPLICATO E RIPROVARE I TEST
$selectComponent = Forms\Components\Select::make('storeId')
->label('Seleziona Store')
->getSearchResultsUsing(function ($search){
return Store::where('name', 'like', '%' . $search . '%')->limit(10)->pluck('name', 'id')->toArray();
})
->searchable()
->required()
->extraAttributes(['id' => 'storeIdSelect']);
if (Store::first() ?? false) {
$selectComponent->default(Store::first()->id);
}
return [ $selectComponent // Assumi che il modello Store abbia 'name' e 'id' ]; } and this is my test it('shows the store selection dropdown', function () { livewire(ScanQR::class) ->assertFormFieldExists('storeId') ->fillForm(['storeId' => 1]) ->assertFormSet(['storeId' => 1]); }); the result it's Failed asserting that null matches expected 1. what im doing wrong ? because if i put options() instead of getSearchResultsUsing() it works normally
return [ $selectComponent // Assumi che il modello Store abbia 'name' e 'id' ]; } and this is my test it('shows the store selection dropdown', function () { livewire(ScanQR::class) ->assertFormFieldExists('storeId') ->fillForm(['storeId' => 1]) ->assertFormSet(['storeId' => 1]); }); the result it's Failed asserting that null matches expected 1. what im doing wrong ? because if i put options() instead of getSearchResultsUsing() it works normally
4 Replies
what happens?
do not find anymore anything
But it perform query to search first store
I mean, when you run tests