You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider the following: A client invokes a LiveComponents LiveAction that does some work. However, that LiveAction fails somehow and raises an UnprocessableEntityHttpException to re-render the Component, e.g. to render an error message.
As an example consider this LiveAction:
#[AsLiveComponent(template: 'component.html.twig')]
class Component {
#[LiveAction]
publicfunctiondoSomething(): void
{
// do some work...if ($success === false) {
// this property is rendered in the template$this->rendered_errors[] = "Oh no, something went wrong ...";
thrownewUnprocessableEntityHttpException();
}
}
}
A test for this LiveAction would look something like this:
class ComponentTest extends KernelTestCase {
use InteractsWithLiveComponents;
publicfunctiontestLiveActionError(): void
{
$component = $this->createLiveComponent(Component::class);
try {
$component = $testComponent->call('doSomething');
} catch (\Throwable$e) {
self::assertInstanceOf(UnprocessableEntityHttpException::class, $e);
// I would expect the response to contain html populated with the values in the "rendered_errors" property// however, this is not the case. It seems the previous content is being retrieved.// $html = $testComponent->response()->getContent();// self::assertStringContainsString('Oh no, something went wrong ...', $html);
}
}
}
As it stands it is impossible to assert the rendered content upon failure of a LiveAction, though I'd love to be proven wrong.
I built some workarounds for this issue, but its kind of a messy hassle honestly. Any ideas?
The text was updated successfully, but these errors were encountered:
Consider the following: A client invokes a LiveComponents LiveAction that does some work. However, that LiveAction fails somehow and raises an UnprocessableEntityHttpException to re-render the Component, e.g. to render an error message.
As an example consider this LiveAction:
A test for this LiveAction would look something like this:
As it stands it is impossible to assert the rendered content upon failure of a LiveAction, though I'd love to be proven wrong.
I built some workarounds for this issue, but its kind of a messy hassle honestly. Any ideas?
The text was updated successfully, but these errors were encountered: