Filter test FAILED `filterTable` doesn't work

I am trying to create a test to validate the filters, but I get the following error. What could be the problem, maybe I missed something in the test setup. It's strange because when you open a web page, these filters work as expected, but in the tests, it doesn't work.
No description
Solution:
I found the reason why it didn't work Here is part of the filter I have ```php...
Jump to solution
1 Reply
Solution
M a k s
M a k s4w ago
I found the reason why it didn't work Here is part of the filter I have
Filter::make('name')
->form([
TextInput::make('name')
->placeholder('Enter name to filter')
->label('Name'),
])
->query(
fn (Builder $query, array $data) => isset($data['name']) && is_string($data['name'])
? $query->whereLike('name', "%{$data['name']}%")
: $query
),
Filter::make('name')
->form([
TextInput::make('name')
->placeholder('Enter name to filter')
->label('Name'),
])
->query(
fn (Builder $query, array $data) => isset($data['name']) && is_string($data['name'])
? $query->whereLike('name', "%{$data['name']}%")
: $query
),
and here is a test that runs successfully
it('applies the `name` filter correctly', function () {
$users = User::factory(5)->create();
$filteredUser = $users->first();
$nonFilteredUsers = $users->reject(fn($user) => $user->name === $filteredUser->name);

livewire(ListUsers::class)
->assertCanSeeTableRecords($users)
->filterTable('name', ['name' => $filteredUser->name])
->assertCountTableRecords(1)
->assertCanSeeTableRecords([$filteredUser])
->assertCanNotSeeTableRecords($nonFilteredUsers);
});
it('applies the `name` filter correctly', function () {
$users = User::factory(5)->create();
$filteredUser = $users->first();
$nonFilteredUsers = $users->reject(fn($user) => $user->name === $filteredUser->name);

livewire(ListUsers::class)
->assertCanSeeTableRecords($users)
->filterTable('name', ['name' => $filteredUser->name])
->assertCountTableRecords(1)
->assertCanSeeTableRecords([$filteredUser])
->assertCanNotSeeTableRecords($nonFilteredUsers);
});
pay attention to the correct writing of the filterTable method with the passing of the necessary parameters

Did you find this page helpful?