Skip to content

Instantly share code, notes, and snippets.

@domthomas-dev
Last active June 30, 2022 13:18
Show Gist options
  • Save domthomas-dev/c92da79d4c6a517e105cea05dd7d1e0e to your computer and use it in GitHub Desktop.
Save domthomas-dev/c92da79d4c6a517e105cea05dd7d1e0e to your computer and use it in GitHub Desktop.
<?php
private function registerTestableLivewireMacro()
{
TestableLivewire::macro('dumpLastErrorBag', function () {
dump($this->lastErrorBag);
return $this;
});
if (function_exists('ray')) {
TestableLivewire::macro('ray', function () {
ray($this->dump());
return $this;
});
}
if (function_exists('ray')) {
TestableLivewire::macro('rayLastErrorBag', function () {
ray($this->lastErrorBag);
return $this;
});
}
}
@domthomas-dev
Copy link
Author

You can use like this :
To see the current ErrorBag

Livewire::test(MyComponent::class)
            ->call('myFunction')
            ->dumpLastErrorBag()
            ->assertHasNoErrors()
            ;

To dump the component state but in ray

Livewire::test(MyComponent::class)
            ->call('myFunction')
            ->ray()
            ->assertHasNoErrors()
            ;

To see the current ErrorBag in ray

Livewire::test(MyComponent::class)
            ->call('myFunction')
            ->rayLastErrorBag()
            ->assertHasNoErrors()
            ;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment