Oct 16, 2025
0
Level 23
how to test livewire compo with sub component? filtering -
so i have a component PostIndex, that renders a view compo 'grid'. this then loops through posts and pass them to a postCard component..
I have A FIlter thing so i can filter by post of some category, or sort them etc.
i am not sure how i would test to say if i filter by category i show only post related to that category? i am a newbie to livewire nad test/pest..
<?php
test('can filter by category', function () {
$post = post::factory()->live()->create([
'category_id' => Category::factory()->create()->id,
]);
$post2 = post::factory()->live()->create([
'category_id' => Category::factory()->create()->id,
]);
Livewire::withQueryParams(['category_id' => $post->category_id])
->test(Index::class);
Livewire::test(postCard::class, ['post' => $post])
->assertSee($post->truncated_title); // this works
Livewire::test(postCard::class, ['post' => $post2])
->assertDontSee($post2->truncated_title); // this doesnt, and not even make snese
});
Please or to participate in this conversation.