PHPackages                             protonemedia/inertiajs-events-laravel-dusk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. protonemedia/inertiajs-events-laravel-dusk

AbandonedArchivedLibrary[Testing &amp; Quality](/categories/testing)

protonemedia/inertiajs-events-laravel-dusk
==========================================

Inertia.js Events for Laravel Dusk

1.3.0(3y ago)2320.5k↓50%6[1 issues](https://github.com/protonemedia/inertiajs-events-laravel-dusk/issues)MITPHPPHP ^8.1|^8.2

Since Apr 8Pushed 1y ago2 watchersCompare

[ Source](https://github.com/protonemedia/inertiajs-events-laravel-dusk)[ Packagist](https://packagist.org/packages/protonemedia/inertiajs-events-laravel-dusk)[ Docs](https://github.com/protonemedia/inertiajs-events-laravel-dusk)[ GitHub Sponsors](https://github.com/pascalbaljet)[ RSS](/packages/protonemedia-inertiajs-events-laravel-dusk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (7)Used By (0)

Inertia.js Events for Laravel Dusk
==================================

[](#inertiajs-events-for-laravel-dusk)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c58c67c8d9cc6db0b67e8fa6d5f792f8f0078aa2d427d142a6ab9499ca63571b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70726f746f6e656d656469612f696e65727469616a732d6576656e74732d6c61726176656c2d6475736b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/protonemedia/inertiajs-events-laravel-dusk)[![run-tests](https://github.com/protonemedia/inertiajs-events-laravel-dusk/workflows/run-tests/badge.svg)](https://github.com/protonemedia/inertiajs-events-laravel-dusk/workflows/run-tests/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/505c95354da307156974491bb7885379330e93ab5239bc72b8865210223ab797/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70726f746f6e656d656469612f696e65727469616a732d6576656e74732d6c61726176656c2d6475736b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/protonemedia/inertiajs-events-laravel-dusk)[![Buy us a tree](https://camo.githubusercontent.com/130148911f548b001b2ac68a32c0a06559977ca60ada3bf480c72ae4ea093175/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f54726565776172652d2546302539462538432542332d6c69676874677265656e)](https://plant.treeware.earth/protonemedia/inertiajs-events-laravel-dusk)

Requirements
------------

[](#requirements)

- PHP 7.4+
- Vue
- Laravel 8.0 and 9.0

Support this package!
---------------------

[](#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](https://github.com/sponsors/pascalbaljet). Keeping track of issues and pull requests takes time, but we're happy to help!

Laravel Splade
--------------

[](#laravel-splade)

**Did you hear about Laravel Splade? 🤩**

It's the *magic* of Inertia.js with the *simplicity* of Blade. [Splade](https://github.com/protonemedia/laravel-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
--------

[](#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](https://protone.media/en/blog/a-package-for-laravel-dusk-to-wait-for-inertiajs-events)

Installation
------------

[](#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](https://inertiajs.com/events).

```
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
-----

[](#usage)

This package provides three helper methods for your Laravel Dusk tests.

### Error

[](#error)

The `waitForInertiaError()` method may be used to wait until the [Error](https://inertiajs.com/events#error) event is fired. You can use it to assert against responses where validation errors are returned.

### Navigate

[](#navigate)

The `waitForInertiaNavigate()` method may be used to wait until the [Navigate](https://inertiajs.com/events#navigate) event is fired. You can use it to assert a user is redirected, for example, after submitting a form.

### Success

[](#success)

The `waitForInertiaSuccess()` method may be used to wait until the [Success](https://inertiajs.com/events#success) event is fired. This is great for testing forms that don't redirect after successfully submitting a form.

### Example test

[](#example-test)

```
