This package adds some nice new Livewire assertions which I was missing while testing my applications using Livewire. If you want to know more about WHY I needed them, check out my blog article.
➡️ Version 2.0
of this package only supports Livewire 3
. Please use a lower version of this package for other Livewire versions.
You can install the package via composer:
composer require christophrumpel/missing-livewire-assertions
The new assertions get added automatically, so you can use them immediately.
Livewire::test(FeedbackForm::class)
->assertPropertyWired('email');
It looks for a string like wire:model="email"
in your component's view file. It also detects variations like wire:model.live="email"
, wire:model.lazy="email"
, wire:model.debounce="email"
, wire:model.lazy.10s="email"
or wire:model.debounce.500ms="email"
.
Livewire::test(FeedbackForm::class)
->assertMethodWired('submit');
It looks for a string like wire:click="submit"
in your component's view file.
Livewire::test(FeedbackForm::class)
->assertMethodWired('$toggle(\'sortAsc\')');
Livewire::test(FeedbackForm::class)
->assertMethodWiredToAction('mouseenter', 'enter');
It looks for a string like wire:mouseenter="enter"
in your component's view file. Also, note that it can also look for any events, like wire:keydown
or wire:custom-event
.
It looks for a string like wire:click="$refresh"
, wire:click="$toggle('sortAsc')
, $dispatch('post-created')
, along with all other magic actions. When testing for magic actions, you must escape single quotes like shown above.
Livewire::test(FeedbackForm::class)
->assertMethodWiredToForm('upload');
It looks for a string like wire:submit.prevent="upload"
in your component's view file.
Livewire::test(FeedbackForm::class)
->assertMethodWiredToEvent('setValue', 'change');
It looks for a string like wire:change.debounce.150ms="setValue"
in your component's view file.
You can also check for actions without any additional modifiers:
Livewire::test(FeedbackForm::class)
->assertMethodWiredToEventWithoutModifiers('reset', 'keyup');
This will match wire:keyup="reset"
, but not wire:keyup.escape="reset"
. You could match that with
Livewire::test(FeedbackForm::class)
->assertMethodWiredToEventWithoutModifiers('reset', 'keyup.escape');
Livewire::test(FeedbackForm::class)
->assertContainsLivewireComponent(CategoryList::class);
You can use the component tag name as well:
Livewire::test(FeedbackForm::class)
->assertContainsLivewireComponent('category-list');
Livewire::test(FeedbackForm::class)
->assertContainsBladeComponent(Button::class);
You can use the component tag name as well:
Livewire::test(FeedbackForm::class)
->assertContainsBladeComponent('button');
Livewire::test(FeedbackForm::class)
->assertSeeBefore('first string', 'second string');
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.