Livewire Plugin

Overview

The Livewire Plugin for Pest provides additional functions for testing your Livewire components.

Source code: github.com/pestphp/pest-plugin-livewire

Installation

Install the Livewire Plugin via the Composer package manager:

1composer require pestphp/pest-plugin-livewire --dev

Available functions

livewire()

You may use the livewire function to test your Livewire components:

1use function Pest\Livewire\livewire;
2 
3it('can be incremented', function () {
4 livewire(Counter::class)
5 ->call('increment')
6 ->assertSee(1);
7 
8 // Same as:
9 $this->livewire(Counter::class)
10 ->call('increment')
11 ->assertSee(1);
12});
13 
14it('can be decremented', function () {
15 livewire(Counter::class)
16 ->call('decrement')
17 ->assertSee(-1);
18 
19 // Same as:
20 $this->livewire(Counter::class)
21 ->call('decrement')
22 ->assertSee(-1);
23});

Of course, the method livewire() can be equally used in your higher order tests:

1it('can be incremented')
2 ->livewire(Counter::class)
3 ->call('increment')
4 ->assertSee(1);
5 
6it('can be decremented')
7 ->livewire(Counter::class)
8 ->call('decrement')
9 ->assertSee(-1);

Finally, for the full list of available Livewire methods, please refer to the Livewire documentation.


Next section: Parallel →