From 500c5ea875051dd2286951506d926e315118c681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Thu, 20 May 2021 23:21:32 +0200 Subject: [PATCH] document testing --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 230f6ec..ffaa9b7 100644 --- a/README.md +++ b/README.md @@ -471,6 +471,31 @@ To use the plugin, use this call **before importing Alpine**: Airwire.plugin('alpine')() ``` +## Testing + +Airwire components are fully testable using fluent syntax: + +```php +// Assertions against responses use send() +test('properties are shared only if they have the Wired attribute', function () { + expect(TestComponent::test() + ->state(['foo' => 'abc', 'bar' => 'xyz']) + ->send() + ->data + )->toBe(['bar' => 'xyz']); // foo is not Wired +}); + +// Assertions against component state use hydrate() +test('properties are shared only if they have the Wired attribute', function () { + expect(TestComponent::test() + ->state(['foo' => 'abc', 'bar' => 'xyz']) + ->hydrate()->bar + )->toBe('xyz'); // foo is not Wired +}); +``` + +You can look at the [package's tests](https://github.com/archtechx/airwire/blob/master/tests/Airwire/ValidationTest.php) to see real-world examples. + ## Protocol spec Airwire components aren't signed or fingerprinted in any way. They're completely stateless just like a REST API, which allows for instantiation from the frontend. This is in contrast to Livewire which doesn't allow any direct state changes — they all have to be "approved" and signed by the backend.