How to test Counting relationships

I'm counting the number of related records in a text column based on the documentation and everything works fine.

Tables\Columns\TextColumn::make('messages_count')
    ->counts('messages'),


How can I test the relationship count with Pest? I tried to test it by chaining assertTableColumnStateSet method to the table component, but no luck so far.

Please tell me if I should provide any further details.

The error:

Failed asserting that a table column with name [messages_count] has value of [1] for record [1] on the [App\Filament\Resources\TelegramUserResource\Pages\ListTelegramUsers] component.

The test:

it('can show the messages count in the table.', function () {
    $message = Message::factory()
        ->has(TelegramUser::factory(), 'telegram_user')
        ->create();

    $telegram_user = $message->telegram_user;

    livewire(TelegramUserResource\Pages\ListTelegramUsers::class)
        ->assertTableColumnStateSet(
            name: 'messages_count',
            value: 1,
            record: $telegram_user,
        );
});
Solution
Not sure, but try using the record ID instead:
record: $telegram_user->id,
Was this page helpful?