© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
1 reply
PepperFM

Unit tests: fill multiselect manually

Hi everyone!
I am trying to test the saving of a many-to-many relationship using multiple selection (common case: the user belongs to many categories), but I cannot figure out what data format this component accepts (key-value or something else)
$categories = Category::query()->inRandomOrder()->take(3)->get();
expect($this->user->categories->count())->toBe(0);
livewire(EditProfile::class)
    ->fillForm([
        'categories' => $categories, // <--- this place i try to find out
    ])
    ->assertFormSet([
        'categories' => $categories->pluck('name', 'id')->toArray(),  // <--- this place i try to find out
    ])
    ->call('save');
expect($this->user->categories->count())->toBe(3);
$categories = Category::query()->inRandomOrder()->take(3)->get();
expect($this->user->categories->count())->toBe(0);
livewire(EditProfile::class)
    ->fillForm([
        'categories' => $categories, // <--- this place i try to find out
    ])
    ->assertFormSet([
        'categories' => $categories->pluck('name', 'id')->toArray(),  // <--- this place i try to find out
    ])
    ->call('save');
expect($this->user->categories->count())->toBe(3);

I have tried various combinations and matching of the collection of input categories, but there is no data in the form (i dumped state via
$this->form->getState()
$this->form->getState()
also in
\Filament\Pages\Auth\EditProfile::save()
\Filament\Pages\Auth\EditProfile::save()
)

Ps: I don't have experience in Livewire
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

Fill Not Working - MultiSelect - With Pivot Table Relationship
FilamentFFilament / ❓┊help
2y ago
Sample of writing unit tests using Pest
FilamentFFilament / ❓┊help
3y ago
Close multiselect
FilamentFFilament / ❓┊help
10mo ago
Translatable multiselect
FilamentFFilament / ❓┊help
3y ago