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 the Form Builder works on Livewire components, you can use the Livewire testing helpers. However, we have custom testing helpers that you can use with forms:

Filling a form

To fill a form with data, pass the data to fillForm():
If you have multiple forms on a Livewire component, you can specify which form you want to fill using fillForm([...], 'createPostForm').
To check that a form has data, use assertFormSet():
If you have multiple forms on a Livewire component, you can specify which form you want to check using assertFormSet([...], 'createPostForm').
You may also find it useful to pass a function to the assertFormSet() method, which allows you to access the form $state and perform additional assertions:
You can return an array from the function if you want Filament to continue to assert the form state after the function has been run.

Validation

Use assertHasFormErrors() to ensure that data is properly validated in a form:
And assertHasNoFormErrors() to ensure there are no validation errors:
If you have multiple forms on a Livewire component, you can pass the name of a specific form as the second parameter like assertHasFormErrors(['title' => 'required'], 'createPostForm') or assertHasNoFormErrors([], 'createPostForm').

Form existence

To check that a Livewire component has a form, use assertFormExists():
If you have multiple forms on a Livewire component, you can pass the name of a specific form like assertFormExists('createPostForm').

Fields

To ensure that a form has a given field, pass the field name to assertFormFieldExists():
You may pass a function as an additional argument in order to assert that a field passes a given “truth test”. This is useful for asserting that a field has a specific configuration:
To assert that a form does not have a given field, pass the field name to assertFormFieldDoesNotExist():
If you have multiple forms on a Livewire component, you can specify which form you want to check for the existence of the field like assertFormFieldExists('title', 'createPostForm').

Hidden fields

To ensure that a field is visible, pass the name to assertFormFieldIsVisible():
Or to ensure that a field is hidden you can pass the name to assertFormFieldIsHidden():
For both assertFormFieldIsHidden() and assertFormFieldIsVisible() you can pass the name of a specific form the field belongs to as the second argument like assertFormFieldIsHidden('title', 'createPostForm').

Disabled fields

To ensure that a field is enabled, pass the name to assertFormFieldIsEnabled():
Or to ensure that a field is disabled you can pass the name to assertFormFieldIsDisabled():
For both assertFormFieldIsEnabled() and assertFormFieldIsDisabled() you can pass the name of a specific form the field belongs to as the second argument like assertFormFieldIsEnabled('title', 'createPostForm').

Layout components

If you need to check if a particular layout component exists rather than a field, you may use assertFormComponentExists(). As layout components do not have names, this method uses the key() provided by the developer:
To assert that a form does not have a given component, pass the component key to assertFormComponentDoesNotExist():
To check if the component exists and passes a given truth test, you can pass a function to the second argument of assertFormComponentExists(), returning true or false if the component passes the test or not:
If you want more informative test results, you can embed an assertion within your truth test callback:

Wizard

To go to a wizard’s next step, use goToNextWizardStep():
You can also go to the previous step by calling goToPreviousWizardStep():
If you want to go to a specific step, use goToWizardStep(), then the assertWizardCurrentStep method which can ensure you are on the desired step without validation errors from the previous:
If you have multiple forms on a single Livewire component, any of the wizard test helpers can accept a formName parameter:

Actions

You can call an action by passing its form component name, and then the name of the action to callFormComponentAction():
To pass an array of data into an action, use the data parameter:
If you ever need to only set an action’s data without immediately calling it, you can use setFormComponentActionData():

Execution

To check if an action has been halted, you can use assertFormComponentActionHalted():

Errors

assertHasNoFormComponentActionErrors() is used to assert that no validation errors occurred when submitting the action form. To check if a validation error has occurred with the data, use assertHasFormComponentActionErrors(), similar to assertHasErrors() in Livewire:
To check if an action is pre-filled with data, you can use the assertFormComponentActionDataSet() method:

Action state

To ensure that an action exists or doesn’t in a form, you can use the assertFormComponentActionExists() or assertFormComponentActionDoesNotExist() method:
To ensure an action is hidden or visible for a user, you can use the assertFormComponentActionHidden() or assertFormComponentActionVisible() methods:
To ensure an action is enabled or disabled for a user, you can use the assertFormComponentActionEnabled() or assertFormComponentActionDisabled() methods:
To check if an action is hidden to a user, you can use the assertFormComponentActionHidden() method:

Button appearance

To ensure an action has the correct label, you can use assertFormComponentActionHasLabel() and assertFormComponentActionDoesNotHaveLabel():
To ensure an action’s button is showing the correct icon, you can use assertFormComponentActionHasIcon() or assertFormComponentActionDoesNotHaveIcon():
To ensure that an action’s button is displaying the right color, you can use assertFormComponentActionHasColor() or assertFormComponentActionDoesNotHaveColor():

URL

To ensure an action has the correct URL, you can use assertFormComponentActionHasUrl(), assertFormComponentActionDoesNotHaveUrl(), assertFormComponentActionShouldOpenUrlInNewTab(), and assertFormComponentActionShouldNotOpenUrlInNewTab():