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 actions are mounted to a Livewire component, 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
You can call an action by passing its name or class tocallAction():
data parameter:
setActionData():
Execution
To check if an action has been halted, you can useassertActionHalted():
Modal content
To assert the content of a modal, you should first mount the action (rather than call it which closes the modal). You can then use Livewire assertions such asassertSee() to assert the modal contains the content that you expect it to:
Errors
assertHasNoActionErrors() 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 assertHasActionErrors(), similar to assertHasErrors() in Livewire:
assertActionDataSet() method:
Action state
To ensure that an action exists or doesn’t, you can use theassertActionExists() or assertActionDoesNotExist() method:
assertActionHidden() or assertActionVisible() methods:
assertActionEnabled() or assertActionDisabled() methods:
assertActionsExistInOrder():
assertActionHidden() method:
Button appearance
To ensure an action has the correct label, you can useassertActionHasLabel() and assertActionDoesNotHaveLabel():
assertActionHasIcon() or assertActionDoesNotHaveIcon():
assertActionHasColor() or assertActionDoesNotHaveColor():
URL
To ensure an action has the correct URL, you can useassertActionHasUrl(), assertActionDoesNotHaveUrl(), assertActionShouldOpenUrlInNewTab(), and assertActionShouldNotOpenUrlInNewTab():