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

Overview

All examples in this guide will be written using Pest. To use Pest’s Livewire plugin for testing, you can follow the installation instructions in the Pest documentation on plugins: Livewire plugin for Pest. However, you can easily adapt this to PHPUnit. Since all pages in the app are Livewire components, we’re just using Livewire testing helpers everywhere. If you’ve never tested Livewire components before, please read this guide from the Livewire docs.

Getting started

Ensure that you are authenticated to access the app in your TestCase:

Testing multiple panels

If you have multiple panels and you would like to test a non-default panel, you will need to tell Filament which panel you are testing. This can be done in the setUp() method of the test case, or you can do it at the start of a particular test. Filament usually does this in a middleware when you access the panel through a request, so if you’re not making a request in your test like when testing a Livewire component, you need to set the current panel manually:

Resources

Pages

List

Routing & render
To ensure that the List page for the PostResource is able to render successfully, generate a page URL, perform a request to this URL and ensure that it is successful:
Table
Filament includes a selection of helpers for testing tables. A full guide to testing tables can be found in the Table Builder documentation. To use a table testing helper, make assertions on the resource’s List page class, which holds the table:

Create

Routing & render
To ensure that the Create page for the PostResource is able to render successfully, generate a page URL, perform a request to this URL and ensure that it is successful:
Creating
You may check that data is correctly saved into the database by calling fillForm() with your form data, and then asserting that the database contains a matching record:
Validation
Use assertHasFormErrors() to ensure that data is properly validated in a form:

Edit

Routing & render
To ensure that the Edit page for the PostResource is able to render successfully, generate a page URL, perform a request to this URL and ensure that it is successful:
Filling existing data
To check that the form is filled with the correct data from the database, you may assertFormSet() that the data in the form matches that of the record:
Saving
You may check that data is correctly saved into the database by calling fillForm() with your form data, and then asserting that the database contains a matching record:
Validation
Use assertHasFormErrors() to ensure that data is properly validated in a form:
Deleting
You can test the DeleteAction using callAction():
You can ensure that a particular user is not able to see a DeleteAction using assertActionHidden():

View

Routing & render
To ensure that the View page for the PostResource is able to render successfully, generate a page URL, perform a request to this URL and ensure that it is successful:
Filling existing data
To check that the form is filled with the correct data from the database, you may assertFormSet() that the data in the form matches that of the record:

Relation managers

Render
To ensure that a relation manager is able to render successfully, mount the Livewire component:
Table
Filament includes a selection of helpers for testing tables. A full guide to testing tables can be found in the Table Builder documentation. To use a table testing helper, make assertions on the relation manager class, which holds the table: