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 3
3
namespace Inertia \Testing ;
4
4
5
5
use Closure ;
6
+ use Illuminate \Support \Arr ;
6
7
7
8
class TestResponseMacros
8
9
{
@@ -27,4 +28,11 @@ public function inertiaPage()
27
28
return AssertableInertia::fromTestResponse ($ this )->toArray ();
28
29
};
29
30
}
31
+
32
+ public function inertiaProps ()
33
+ {
34
+ return function (?string $ propName = null ) {
35
+ return Arr::get ($ this ->inertiaPage ()['props ' ], $ propName );
36
+ };
37
+ }
30
38
}
Original file line number Diff line number Diff line change @@ -50,4 +50,30 @@ public function test_it_can_retrieve_the_inertia_page(): void
50
50
$ this ->assertFalse ($ page ['clearHistory ' ]);
51
51
});
52
52
}
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
+ }
53
79
}
You can’t perform that action at this time.
0 commit comments