Giter VIP home page Giter VIP logo

missing-livewire-assertions's Introduction

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

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.

missing-livewire-assertions's People

Contributors

christophrumpel avatar nuernbergera avatar peterfox avatar joshualukecaine avatar gertjanroke avatar cheesegrits avatar jonjakoblich avatar bretterer avatar mpociot avatar michael-rubel avatar dostrog avatar titantwentyone avatar abenerd avatar leganz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.