Skip to main content
You are currently viewing the documentation for Filament 4.x, which is a previous version of Filament.Looking for the current stable version? Visit the 5.x documentation.

Testing that a table can render

To ensure a table component renders, use the assertSuccessful() Livewire helper:
To test which records are shown, you can use assertCanSeeTableRecords(), assertCanNotSeeTableRecords() and assertCountTableRecords():
If your table uses pagination, assertCanSeeTableRecords() will only check for records on the first page. To switch page, call call('gotoPage', 2).
If your table uses deferLoading(), you should call loadTable() before assertCanSeeTableRecords().

Testing columns

To ensure that a certain column is rendered, pass the column name to assertCanRenderTableColumn():
This helper will get the HTML for this column, and check that it is present in the table. For testing that a column is not rendered, you can use assertCanNotRenderTableColumn():
This helper will assert that the HTML for this column is not shown by default in the present table.

Testing that a column can be searched

To search the table, call the searchTable() method with your search query. You can then use assertCanSeeTableRecords() to check your filtered table records, and use assertCanNotSeeTableRecords() to assert that some records are no longer in the table:
To search individual columns, you can pass an array of searches to searchTableColumns():

Testing that a column can be sorted

To sort table records, you can call sortTable(), passing the name of the column to sort by. You can use 'desc' in the second parameter of sortTable() to reverse the sorting direction. Once the table is sorted, you can ensure that the table records are rendered in order using assertCanSeeTableRecords() with the inOrder parameter:
Filament tables use a SQL order statement to sort records before they are output. Different database drivers can use different sorting strategies, and they can differ from PHP’s own sorting strategy, so you should ensure that test records are sorted using orderBy() on a database query rather than sortBy() on a collection of models.

Testing the state of a column

To assert that a certain column has a state or does not have a state for a record you can use assertTableColumnStateSet() and assertTableColumnStateNotSet():
To assert that a certain column has a formatted state or does not have a formatted state for a record you can use assertTableColumnFormattedStateSet() and assertTableColumnFormattedStateNotSet():

Testing the existence of a column

To ensure that a column exists, you can use the assertTableColumnExists() method:
You may pass a function as an additional argument to assert that a column passes a given “truth test”. This is useful for asserting that a column has a specific configuration. You can also pass in a record as the third parameter, which is useful if your check is dependent on which table row is being rendered:

Testing the visibility of a column

To ensure that a particular user cannot see a column, you can use the assertTableColumnVisible() and assertTableColumnHidden() methods:

Testing the description of a column

To ensure a column has the correct description above or below you can use the assertTableColumnHasDescription() and assertTableColumnDoesNotHaveDescription() methods:

Testing the extra attributes of a column

To ensure that a column has the correct extra attributes, you can use the assertTableColumnHasExtraAttributes() and assertTableColumnDoesNotHaveExtraAttributes() methods:

Testing the options in a SelectColumn

If you have a select column, you can ensure it has the correct options with assertTableSelectColumnHasOptions() and assertTableSelectColumnDoesNotHaveOptions():

Testing filters

To filter the table records, you can use the filterTable() method, along with assertCanSeeTableRecords() and assertCanNotSeeTableRecords():
For a simple filter, this will just enable the filter. If you’d like to set the value of a SelectFilter or TernaryFilter, pass the value as a second argument:

Resetting filters in a test

To reset all filters to their original state, call resetTableFilters():

Removing filters in a test

To remove a single filter you can use removeTableFilter():
To remove all filters you can use removeTableFilters():

Testing the visibility of a filter

To ensure that a particular user cannot see a filter, you can use the assertTableFilterVisible() and assertTableFilterHidden() methods:

Testing the existence of a filter

To ensure that a filter exists, you can use the assertTableFilterExists() method:
You may pass a function as an additional argument to assert that a filter passes a given “truth test”. This is useful for asserting that a filter has a specific configuration:

Testing summaries

To test that a summary calculation is working, you may use the assertTableColumnSummarySet() method:
The first argument is the column name, the second is the summarizer ID, and the third is the expected value. Note that the expected and actual values are normalized, such that 123.12 is considered the same as "123.12", and ['Fred', 'Jim'] is the same as ['Jim', 'Fred']. You may set a summarizer ID by passing it to the make() method:
The ID should be unique between summarizers in that column.

Testing summaries on only one pagination page

To calculate the average for only one pagination page, use the isCurrentPaginationPageOnly argument:

Testing a range summarizer

To test a range, pass the minimum and maximum value into a tuple-style [$minimum, $maximum] array:

Testing toggleable columns

By default, only columns that are toggled on by default in the table will be rendered and testable. You can toggle all columns in the table on using toggleAllTableColumns():
You can also toggle all columns off using toggleAllTableColumns(false):