Download the PHP package joshhanley/livewire-dusk-testbench without Composer
On this page you can find all versions of the php package joshhanley/livewire-dusk-testbench. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download joshhanley/livewire-dusk-testbench
More information about joshhanley/livewire-dusk-testbench
Files in joshhanley/livewire-dusk-testbench
Package livewire-dusk-testbench
Short Description A Laravel Dusk testing helper for Livewire package development.
License MIT
Informations about the package livewire-dusk-testbench
Livewire Dusk Testbench
Livewire Dusk Testbench is a convenience wrapper around Orchestral Testbench Dusk to make testing Livewire components in your package using Laravel Dusk easier.
The code was developed by Caleb Porzio for testing Livewire itself, and packaged up by Josh Hanley for use by others.
Getting Started
It's recommended you read the documentation of these packages before going through this document:
Installation
To install through composer, run the following command from terminal:
Upgrading from V2 of this package
- App key in phpunit.xml is no longer needed.
- Signature of
public array $packageProviders = [];
now has array type definition. configureViewDirectory()
method has been renamed toviewsDirectory
and should now return a string of the path for the views directory. Astring
return type is also required.$testsNamespace
property andconfigureTestsDirectory()
method are no longer needed so can be deleted.tweatApplicationHook()
method is now astatic
method.- Almost all of the items listed in the
Possible Overrides
in the old README are no longer relevant and can be removed. Remaining ones are listed in that section below. - Tests no longer need the
$this->browse()
method to be called, instead you can callLivewire::visit(MyComponent::class)
and the first parameter of Livewire:visit is no longer$browser
and instead is your component class. See below examples:
Old test structure:
New test structure:
Usage
To use this package you need to:
- Setup your base browser testcase
- Register your package service providers (if required)
- Setup layout views (if required)
- Configure test directory and namespace (if required)
Then you are ready to start testing.
There are other configuration options you can override depending on your needs.
Setup Browser TestCase
To use Livewire Dusk Testbench, all you need to do is extend LivewireDuskTestbench\TestCase
instead of Orchestra\Testbench\Dusk\TestCase
in your dusk tests.
Or configure this in your base browser testcase:
Register Package Service Providers
Register your package services providers in $packageProviders property to ensure they are loaded for testing:
Setup Layout Views
To add other packages to your app layout for testing with, such as AlpineJS, you will need to create a custom layout.
Create your own app layout by creating a views/components/layouts
folder somewhere in your package and add a app.blade.php
file inside the layouts folder.
Populate your app layout as required.
Then set your base view folder by overridding viewsDirectory
method to return a path to the views
folder you created.
For Example
A good location to store your views folder and app layout would be in your Dusk browser tests folder.
In the root of your package, create the following directories and file
tests/Browser/views/components/layouts/app.blade.php
Then in your tests/Browser/TestCase.php
file add:
Livewire Dusk Macros
Livewire comes with a bunch of Dusk macros which you can use.
Check them out in the Livewire source in 'livewire/src/Features/SupportTesting/DuskBrowserMacros.php'.
Demo Package
A demo package has been setup which gives a sample of how this package can be used. Check it out here
Possible Overrides
Below is a list of some of the settings you can override inside your browser TestCase file to suit your testing needs. Listed below are the defaults:
Troubleshooting
This is just a convenience wrapper around Orchestral Testbench Dusk to make testing Livewire Components in your package easier.
Consult the documentation for the relevant packages for troubleshooting.
All versions of livewire-dusk-testbench with dependencies
livewire/livewire Version ^3.1|dev-master
orchestra/testbench-dusk Version ^8.0|^9.0
psy/psysh Version ^0.11.1