protonemedia / inertiajs-events-laravel-dusk
Inertia.js Events for Laravel Dusk
Fund package maintenance!
pascalbaljet
Installs: 19 267
Dependents: 0
Suggesters: 0
Security: 0
Stars: 22
Watchers: 4
Forks: 5
Open Issues: 1
Requires
- php: ^8.1|^8.2
- illuminate/support: ^9.0|^10.0
- laravel/dusk: ^6.15|^7.0
- nesbot/carbon: ^2.66
Requires (Dev)
- mockery/mockery: ^1.4.4
- orchestra/testbench: ^7.0|^8.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2023-08-17 21:58:26 UTC
README
Inertia.js Events for Laravel Dusk
Requirements
- PHP 7.4+
- Vue
- Laravel 8.0 and 9.0
Support this package!
❤️ We proudly support the community by developing Laravel packages and giving them away for free. If this package saves you time or if you're relying on it professionally, please consider sponsoring the maintenance and development. Keeping track of issues and pull requests takes time, but we're happy to help!
Laravel Splade
Did you hear about Laravel Splade? 🤩
It's the magic of Inertia.js with the simplicity of Blade. Splade provides a super easy way to build Single Page Applications using Blade templates. Besides that magic SPA-feeling, it comes with more than ten components to sparkle your app and make it interactive, all without ever leaving Blade.
Blogpost
If you want to know more about the background of this package, please read the blogpost: A package for Laravel Dusk to wait for Inertia.js events
Installation
You can install the package via composer:
composer require protonemedia/inertiajs-events-laravel-dusk --dev
Add the inertiaEventsCount
object to your main JavaScript file, somewhere above the creation of the Vue application instance.
window.inertiaEventsCount = { navigateCount: 0, successCount: 0, errorCount: 0, }
In the creation of the Vue application instance, use the mounted
method to register the event listeners.
import { Inertia } from '@inertiajs/inertia' new Vue({ mounted() { Inertia.on('navigate', (event) => { window.inertiaEventsCount.navigateCount++; }) Inertia.on('success', (event) => { window.inertiaEventsCount.successCount++; }) Inertia.on('error', (event) => { window.inertiaEventsCount.errorCount++; }) } })
Usage
This package provides three helper methods for your Laravel Dusk tests.
Error
The waitForInertiaError()
method may be used to wait until the Error event is fired. You can use it to assert against responses where validation errors are returned.
Navigate
The waitForInertiaNavigate()
method may be used to wait until the Navigate event is fired. You can use it to assert a user is redirected, for example, after submitting a form.
Success
The waitForInertiaSuccess()
method may be used to wait until the Success event is fired. This is great for testing forms that don't redirect after successfully submitting a form.
Example test
<?php namespace Tests\Browser; use App\Models\User; use Illuminate\Foundation\Testing\DatabaseMigrations; use Tests\DuskTestCase; class ExampleTest extends DuskTestCase { use DatabaseMigrations; /** * A basic browser test example. * * @return void */ public function it_can_store_a_user_and_redirect_back_to_the_index_route() { $this->browse(function ($browser) { $browser->loginAs(User::first()) ->visit(route('user.create')) ->type('name', 'New User') ->press('Submit') ->waitForInertiaNavigate() ->assertRouteIs('user.index') ->assertSee('User Added!'); }); } }
Testing
composer test
Changelog
Please see CHANGELOG for more information about what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Other Laravel packages
Laravel Analytics Event Tracking
: Laravel package to easily send events to Google Analytics.Laravel Blade On Demand
: Laravel package to compile Blade templates in memory.Laravel Cross Eloquent Search
: Laravel package to search through multiple Eloquent models.Laravel Eloquent Scope as Select
: Stop duplicating your Eloquent query scopes and constraints in PHP. This package lets you re-use your query scopes and constraints by adding them as a subquery.Laravel Eloquent Where Not
: This Laravel package allows you to flip/invert an Eloquent scope, or really any query constraint.Laravel FFMpeg
: This package provides an integration with FFmpeg for Laravel. The storage of the files is handled by Laravel's Filesystem.Laravel Form Components
: Blade components to rapidly build forms with Tailwind CSS Custom Forms and Bootstrap 4. Supports validation, model binding, default values, translations, includes default vendor styling and fully customizable!Laravel Paddle
: Paddle.com API integration for Laravel with support for webhooks/events.Laravel Verify New Email
: This package adds support for verifying new email addresses: when a user updates its email address, it won't replace the old one until the new one is verified.Laravel WebDAV
: WebDAV driver for Laravel's Filesystem.
Security
If you discover any security related issues, please email pascal@protone.media instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Treeware
This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.