• Stars
    star
    133
  • Rank 271,787 (Top 6 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 3 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Adding the missing Livewire assertions to your Laravel project

CleanShot 2023-02-14 at 17 17 03@2x

This Package Adds Missing Livewire Test Assertions

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.

Installation

You can install the package via composer:

composer require christophrumpel/missing-livewire-assertions

Usage

The new assertions get added automatically, so you can use them immediately.

Check if a Livewire property is wired to an HTML field

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".

Check if a Livewire method is wired to an HTML field

Livewire::test(FeedbackForm::class)
    ->assertMethodWired('submit');

It looks for a string like wire:click="submit" in your component's view file.

Check if a Livewire magic action is wired to an HTML field

Livewire::test(FeedbackForm::class)
    ->assertMethodWired('$toggle(\'sortAsc\')');

Check if a generic Livewire method is wired to an HTML field

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.

Check if a Livewire method is wired to an HTML form

Livewire::test(FeedbackForm::class)
    ->assertMethodWiredToForm('upload');

It looks for a string like wire:submit.prevent="upload" in your component's view file.

Check if a Livewire method is wired to a specific javascript event

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');

Check if a Livewire component contains another Livewire component

Livewire::test(FeedbackForm::class)
    ->assertContainsLivewireComponent(CategoryList::class);

You can use the component tag name as well:

Livewire::test(FeedbackForm::class)
    ->assertContainsLivewireComponent('category-list');

Check if a Livewire component contains a Blade component

Livewire::test(FeedbackForm::class)
    ->assertContainsBladeComponent(Button::class);

You can use the component tag name as well:

Livewire::test(FeedbackForm::class)
    ->assertContainsBladeComponent('button');

Check to see if a string comes before another string

Livewire::test(FeedbackForm::class)
    ->assertSeeBefore('first string', 'second string');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

More Repositories

1

laravel-factories-reloaded

๐ŸญThis package lets you create factory classes for your Laravel project.
PHP
381
star
2

larastreamers

There is no better way to learn than by watching other developers code live. Find out who is streaming next in the Laravel world.
PHP
231
star
3

chatbot-php-boilerplate

This package makes it simple to start building a chatbot in PHP. Give me 10 minutes of your time and I will give you a chatbot starter setup.
PHP
118
star
4

nova-notifications

A Laravel Nova tool overview and handle Laravel Notifications
PHP
77
star
5

christoph-rumpel.com-old

My personal blog
PHP
52
star
6

blog-laravel-real-time-notifications

PHP
46
star
7

laravel-quiz-chatbot

PHP
44
star
8

what-you-can-test-in-laravel

PHP
42
star
9

christoph-rumpel.com

This is my personal blog https://christoph-rumpel.com
PHP
30
star
10

laravel-command-file-picker

This package lets you show a list of files or classes to choose from during a Laravel command.
PHP
9
star
11

talks-the-final-service-container

PHP
6
star
12

blog-gulp-setup

All of the code from my article on a Laravel Gulp setup
CSS
5
star
13

bcwp-laraconeu-chatbot

This the code for the Laracon EU chatbot from my book "Build Chatbots with PHP"
PHP
5
star
14

cv

My personal CV
3
star
15

getting-started-with-reverb

Blade
3
star
16

bcwp-php-starter

This is the PHP starter project from my book "Build Chatbots with PHP"
PHP
2
star
17

christophrumpel.github.io

My personal static blog (not used anymore)
CSS
2
star
18

raspberrypi-realtime-website-tracking

Show an active user of a site in realtime on elemetns connected to a Rasperry Pi.
Python
2
star
19

getting-started-with-tdd-in-php

Example code of "Getting Started with TDD in PHP"
PHP
1
star
20

fair-product-prices

PHP
1
star
21

botman57

PHP
1
star
22

dotfiles-old

My personal dotfiles
Vim Script
1
star
23

christoph-rumpel.com_old

My personal portfolio site
PHP
1
star
24

phpstan-demo-public

PHP
1
star
25

laracon-notes-template

A Laracon EU notes template
1
star