File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 33namespace Inertia \Testing ;
44
55use Closure ;
6+ use Illuminate \Support \Arr ;
67
78class TestResponseMacros
89{
@@ -27,4 +28,11 @@ public function inertiaPage()
2728 return AssertableInertia::fromTestResponse ($ this )->toArray ();
2829 };
2930 }
31+
32+ public function inertiaProps ()
33+ {
34+ return function (?string $ propName = null ) {
35+ return Arr::get ($ this ->inertiaPage ()['props ' ], $ propName );
36+ };
37+ }
3038}
Original file line number Diff line number Diff line change @@ -50,4 +50,30 @@ public function test_it_can_retrieve_the_inertia_page(): void
5050 $ this ->assertFalse ($ page ['clearHistory ' ]);
5151 });
5252 }
53+
54+ public function test_it_can_retrieve_the_inertia_props (): void
55+ {
56+ $ props = ['bar ' => 'baz ' ];
57+ $ response = $ this ->makeMockRequest (
58+ Inertia::render ('foo ' , $ props )
59+ );
60+
61+ $ this ->assertSame ($ props , $ response ->inertiaProps ());
62+ }
63+
64+ public function test_it_can_retrieve_nested_inertia_prop_values_with_dot_notation (): void
65+ {
66+ $ response = $ this ->makeMockRequest (
67+ Inertia::render ('foo ' , [
68+ 'bar ' => ['baz ' => 'qux ' ],
69+ 'users ' => [
70+ ['name ' => 'John ' ],
71+ ['name ' => 'Jane ' ],
72+ ],
73+ ])
74+ );
75+
76+ $ this ->assertSame ('qux ' , $ response ->inertiaProps ('bar.baz ' ));
77+ $ this ->assertSame ('John ' , $ response ->inertiaProps ('users.0.name ' ));
78+ }
5379}
You can’t perform that action at this time.
0 commit comments