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.
<?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;
');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment