diff --git a/src/Testing/AssertableInertia.php b/src/Testing/AssertableInertia.php index 4f455e85..7529c2e5 100644 --- a/src/Testing/AssertableInertia.php +++ b/src/Testing/AssertableInertia.php @@ -192,7 +192,9 @@ public function reload(?Closure $callback = null, array|string|null $only = null public function reloadOnly(array|string $only, ?Closure $callback = null): self { return $this->reload(only: $only, callback: function (AssertableInertia $assertable) use ($only, $callback) { - $assertable->hasAll(explode(',', $only)); + $props = is_array($only) ? $only : explode(',', $only); + + $assertable->hasAll($props); if ($callback) { $callback($assertable); @@ -208,7 +210,9 @@ public function reloadOnly(array|string $only, ?Closure $callback = null): self public function reloadExcept(array|string $except, ?Closure $callback = null): self { return $this->reload(except: $except, callback: function (AssertableInertia $assertable) use ($except, $callback) { - $assertable->missingAll(explode(',', $except)); + $props = is_array($except) ? $except : explode(',', $except); + + $assertable->missingAll($props); if ($callback) { $callback($assertable); diff --git a/tests/Testing/AssertableInertiaTest.php b/tests/Testing/AssertableInertiaTest.php index c4e6644c..6792197a 100644 --- a/tests/Testing/AssertableInertiaTest.php +++ b/tests/Testing/AssertableInertiaTest.php @@ -249,6 +249,36 @@ public function test_lazy_props_can_be_evaluated(): void $this->assertTrue($called); } + public function test_lazy_props_can_be_evaluated_when_only_is_array(): void + { + $response = $this->makeMockRequest( + Inertia::render('foo', [ + 'foo' => 'bar', + 'lazy1' => Inertia::optional(fn () => 'baz'), + 'lazy2' => Inertia::optional(fn () => 'qux'), + ]) + ); + + $called = false; + + $response->assertInertia(function ($inertia) use (&$called) { + $inertia->where('foo', 'bar'); + $inertia->missing('lazy1'); + $inertia->missing('lazy2'); + + $result = $inertia->reloadOnly(['lazy1'], function ($inertia) use (&$called) { + $inertia->missing('foo'); + $inertia->where('lazy1', 'baz'); + $inertia->missing('lazy2'); + $called = true; + }); + + $this->assertSame($result, $inertia); + }); + + $this->assertTrue($called); + } + public function test_lazy_props_can_be_evaluated_with_except(): void { $response = $this->makeMockRequest( @@ -277,6 +307,34 @@ public function test_lazy_props_can_be_evaluated_with_except(): void $this->assertTrue($called); } + public function test_lazy_props_can_be_evaluated_with_except_when_except_is_array(): void + { + $response = $this->makeMockRequest( + Inertia::render('foo', [ + 'foo' => 'bar', + 'lazy1' => Inertia::lazy(fn () => 'baz'), + 'lazy2' => Inertia::lazy(fn () => 'qux'), + ]) + ); + + $called = false; + + $response->assertInertia(function ($inertia) use (&$called) { + $inertia->where('foo', 'bar'); + $inertia->missing('lazy1'); + $inertia->missing('lazy2'); + + $inertia->reloadExcept(['lazy1'], function ($inertia) use (&$called) { + $inertia->where('foo', 'bar'); + $inertia->missing('lazy1'); + $inertia->where('lazy2', 'qux'); + $called = true; + }); + }); + + $this->assertTrue($called); + } + public function test_assert_against_deferred_props(): void { $response = $this->makeMockRequest(