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.
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:
4 Replies
Just out of curiosity, are you sure you need this test? Maybe I'm missing something but it seems like this is just testing that the
->counts()
method works. Filament likely has a test for that internally.I just wanted to make sure. Now that you mentioned it, I should probably focus on testing the relationship itself, rather than testing the Filament which we already know works fine.
Nevertheless, do you think it is possible to test it?
Solution
Not sure, but try using the record ID instead:
It works! Not what I expected, but gonna close this as resolved anyway. Thank you very much, Patrick!