PHPackages                             joshhanley/livewire-dusk-testbench - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. joshhanley/livewire-dusk-testbench

ActiveLibrary[Testing &amp; Quality](/categories/testing)

joshhanley/livewire-dusk-testbench
==================================

A Laravel Dusk testing helper for Livewire package development.

v2.0.0(3y ago)174.0k↓50%21MITPHPPHP ^7.4|^8.0CI passing

Since Jan 12Pushed 1y ago2 watchersCompare

[ Source](https://github.com/joshhanley/livewire-dusk-testbench)[ Packagist](https://packagist.org/packages/joshhanley/livewire-dusk-testbench)[ RSS](/packages/joshhanley-livewire-dusk-testbench/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (16)Used By (1)

Livewire Dusk Testbench
=======================

[](#livewire-dusk-testbench)

Livewire Dusk Testbench is a convenience wrapper around [Orchestral Testbench Dusk](https://github.com/orchestral/testbench-dusk) to make testing [Livewire](https://github.com/livewire/livewire) components in your package using [Laravel Dusk](https://laravel.com/docs/dusk) easier.

The code was developed by [Caleb Porzio](https://github.com/calebporzio) for testing Livewire itself, and packaged up by [Josh Hanley](https://github.com/joshhanley) for use by others.

Getting Started
---------------

[](#getting-started)

It's recommended you read the documentation of these packages before going through this document:

- [Livewire](https://laravel-livewire.com/docs)
- [Orchestra Testbench Dusk](https://github.com/orchestral/testbench-dusk)
- [Laravel Dusk](https://laravel.com/docs/dusk)
- [Orchestra Testbench](https://github.com/orchestral/testbench)
- [Laravel Package Development](https://laravel.com/docs/packages)

Installation
------------

[](#installation)

To install through composer, run the following command from terminal:

```
composer require --dev joshhanley/livewire-dusk-testbench
```

Upgrading from V2 of this package
---------------------------------

[](#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 to `viewsDirectory` and should now return a string of the path for the views directory. A `string` return type is also required.
- `$testsNamespace` property and `configureTestsDirectory()` method are no longer needed so can be deleted.
- `tweatApplicationHook()` method is now a `static` 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 call `Livewire::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:

```
/** @test */
public function it_can_count()
{
    $this->browse(function (Browser $browser) {
        Livewire::visit($browser, CounterComponent::class)
            // Assertions here
            ;
    });
}
```

New test structure:

```
/** @test */
public function it_can_count()
{
    Livewire::visit(CounterComponent::class)
        // Assertions here
        ;
}
```

Usage
-----

[](#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

[](#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:

```
