Skip to content

Commit 54116e3

Browse files
committed
Add documentation
1 parent 33580ad commit 54116e3

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/LiveComponent/doc/index.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,6 +3829,44 @@ uses Symfony's test client to render and make requests to your components::
38293829
The ``InteractsWithLiveComponents`` trait can only be used in tests that extend
38303830
``Symfony\Bundle\FrameworkBundle\Test\KernelTestCase``.
38313831

3832+
When testing live components, you can assert whether a specific event has been emitted using new assertion methods provided by the ``InteractsWithLiveComponents`` trait.
3833+
3834+
Use the following assertions to verify event emissions from your live component::
3835+
3836+
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
3837+
use Symfony\UX\LiveComponent\Test\InteractsWithLiveComponents;
3838+
3839+
class MyComponentTest extends KernelTestCase
3840+
{
3841+
use InteractsWithLiveComponents;
3842+
3843+
public function testEventEmission(): void
3844+
{
3845+
$testComponent = $this->createLiveComponent(
3846+
name: 'MyComponent',
3847+
data: ['foo' => 'bar'],
3848+
);
3849+
3850+
// Call an action that emits an event
3851+
$render = $testComponent->call('triggerEvent')->render();
3852+
3853+
// Assert that the event was emitted with arguments
3854+
$this->componentHasEmittedEvent($render, 'event-name', [
3855+
'eventArg1' => 'value',
3856+
]);
3857+
3858+
// Assert that a specific event was *not* emitted
3859+
$this->assertComponentNotEmitEvent($render, 'unwanted-event');
3860+
}
3861+
}
3862+
3863+
.. note::
3864+
3865+
These assertions are only available when using the ``InteractsWithLiveComponents`` trait in a test class that extends
3866+
``Symfony\Bundle\FrameworkBundle\Test\KernelTestCase``.
3867+
3868+
---
3869+
38323870
Test LiveCollectionType
38333871
~~~~~~~~~~~~~~~~~~~~~~~
38343872

0 commit comments

Comments
 (0)