Skip to content

Commit 0391cc7

Browse files
feat: add inertiaProps method for easier prop extraction in tests
This commit introduces a new `inertiaProps` method in the `TestResponseMacros` class. The method simplifies the process of retrieving specific props from an Inertia.js response during testing. It uses Laravel's `Arr::get` utility to handle nested properties and returns a default value if the specified prop is not found. Example usage: $response->inertiaProps('user.name'); This enhancement improves test readability and usability for Inertia.js developers.
1 parent 0259e37 commit 0391cc7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Testing/TestResponseMacros.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Inertia\Testing;
44

55
use Closure;
6+
use Illuminate\Support\Arr;
67

78
class TestResponseMacros
89
{
@@ -27,4 +28,12 @@ public function inertiaPage()
2728
return AssertableInertia::fromTestResponse($this)->toArray();
2829
};
2930
}
31+
32+
public function inertiaProps(?string $propName = null): mixed
33+
{
34+
return Arr::get(
35+
$this->inertiaPage()['props'] ?? [],
36+
$propName
37+
);
38+
}
3039
}

0 commit comments

Comments
 (0)