From ea4c093c6f6649cce9fc3f90e9b625f20bea7910 Mon Sep 17 00:00:00 2001 From: Brent Kelly Date: Fri, 9 Aug 2024 11:26:00 +1200 Subject: [PATCH] update action testing documentation to include testing modals --- packages/actions/docs/09-testing.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/actions/docs/09-testing.md b/packages/actions/docs/09-testing.md index 3c4b5e5efa..6501667db4 100644 --- a/packages/actions/docs/09-testing.md +++ b/packages/actions/docs/09-testing.md @@ -86,6 +86,25 @@ it('stops sending if invoice has no email address', function () { }); ``` +## Testing modal content + +To assert against the content of a modal, you should first mount the action (rather than call it which resolves the modal). You can then use [livewire assertions](https://livewire.laravel.com/docs/testing#assertions) such as `assertSee` to assert the modal has rendered as you expect: + +```php +use function Pest\Livewire\livewire; + +it('confirms the target address before sending', function () { + $invoice = Invoice::factory()->create(); + $recipientEmail = $invoice->company->primaryContact->email; + + livewire(EditInvoice::class, [ + 'invoice' => $invoice, + ]) + ->mountAction('send') + ->assertSee($recipientEmail); +}); +``` + ## Errors `assertHasNoActionErrors()` is used to assert that no validation errors occurred when submitting the action form. @@ -126,7 +145,7 @@ it('can send invoices to the primary contact by default', function () { ]) ->callMountedAction() ->assertHasNoActionErrors(); - + expect($invoice->refresh()) ->isSent()->toBeTrue() ->recipient_email->toBe($recipientEmail);