Skip to content

Instantly share code, notes, and snippets.

@jhoff
Created July 15, 2020 18:49
Show Gist options
  • Save jhoff/4b83b7dc39ffc3e8c3c7c808c2dedd0c to your computer and use it in GitHub Desktop.
Save jhoff/4b83b7dc39ffc3e8c3c7c808c2dedd0c to your computer and use it in GitHub Desktop.

Revisions

  1. jhoff created this gist Jul 15, 2020.
    21 changes: 21 additions & 0 deletions LivewireDuskHelpers.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    <?php

    use Laravel\Dusk\Browser;

    Browser::macro('waitUntilWire', function ($component, $key, $value, $seconds = null) {
    return $this->waitUsing($seconds, 100, function () use ($component, $key, $value) {
    return $value == $this->wireAttribute($component, $key);
    });
    });

    Browser::macro('waitUntilWireNot', function ($component, $key, $value, $seconds = null) {
    return $this->waitUsing($seconds, 100, function () use ($component, $key, $value) {
    return $value != $this->wireAttribute($component, $key);
    });
    });

    Browser::macro('wireAttribute', function ($component, $key) {
    return $this->driver->executeScript('
    return (component = window._.first(window._.filter(window.livewire.components.components(), {name: "' . $component . '"}))) ? component.data["' . $key . '"] : undefined;
    ');
    });