|
6 | 6 | use Illuminate\Foundation\Auth\User; |
7 | 7 | use Illuminate\Database\Eloquent\Model; |
8 | 8 | use PHPUnit\Framework\AssertionFailedError; |
| 9 | +use Illuminate\Http\Resources\Json\JsonResource; |
9 | 10 |
|
10 | 11 | class AssertionsTest extends TestCase |
11 | 12 | { |
@@ -278,6 +279,73 @@ public function test_the_inertia_page_does_not_have_a_nested_prop_with_a_value_u |
278 | 279 | $response->assertInertiaHas('example.nested', $userB); |
279 | 280 | } |
280 | 281 |
|
| 282 | + public function test_the_inertia_page_has_a_prop_with_a_value_using_a_responsable() |
| 283 | + { |
| 284 | + Model::unguard(); |
| 285 | + $user = User::make(['name' => 'Example']); |
| 286 | + $resource = JsonResource::collection([$user, $user]); |
| 287 | + |
| 288 | + $response = $this->makeMockResponse( |
| 289 | + Inertia::render('test-component', [ |
| 290 | + 'example' => $resource, |
| 291 | + ]) |
| 292 | + ); |
| 293 | + |
| 294 | + $response->assertInertiaHas('example', $resource); |
| 295 | + } |
| 296 | + |
| 297 | + public function test_the_inertia_page_does_not_have_a_prop_with_a_value_using_a_responsable() |
| 298 | + { |
| 299 | + Model::unguard(); |
| 300 | + $resourceA = JsonResource::make(User::make(['name' => 'Another'])); |
| 301 | + $resourceB = JsonResource::make(User::make(['name' => 'Example'])); |
| 302 | + |
| 303 | + $response = $this->makeMockResponse( |
| 304 | + Inertia::render('test-component', [ |
| 305 | + 'example' => $resourceA, |
| 306 | + ]) |
| 307 | + ); |
| 308 | + |
| 309 | + $this->expectException(AssertionFailedError::class); |
| 310 | + |
| 311 | + $response->assertInertiaHas('example', $resourceB); |
| 312 | + } |
| 313 | + |
| 314 | + public function test_the_inertia_page_has_a_nested_prop_with_a_value_using_a_responsable() |
| 315 | + { |
| 316 | + Model::unguard(); |
| 317 | + $resource = JsonResource::make(User::make(['name' => 'Another'])); |
| 318 | + |
| 319 | + $response = $this->makeMockResponse( |
| 320 | + Inertia::render('test-component', [ |
| 321 | + 'example' => [ |
| 322 | + 'nested' => $resource, |
| 323 | + ], |
| 324 | + ]) |
| 325 | + ); |
| 326 | + |
| 327 | + $response->assertInertiaHas('example.nested', $resource); |
| 328 | + } |
| 329 | + |
| 330 | + public function test_the_inertia_page_does_not_have_a_nested_prop_with_a_value_using_a_responsable() |
| 331 | + { |
| 332 | + Model::unguard(); |
| 333 | + $resourceA = JsonResource::make(User::make(['name' => 'Another'])); |
| 334 | + $resourceB = JsonResource::make(User::make(['name' => 'Example'])); |
| 335 | + |
| 336 | + $response = $this->makeMockResponse( |
| 337 | + Inertia::render('test-component', [ |
| 338 | + 'example' => [ |
| 339 | + 'nested' => $resourceA, |
| 340 | + ], |
| 341 | + ]) |
| 342 | + ); |
| 343 | + |
| 344 | + $this->expectException(AssertionFailedError::class); |
| 345 | + |
| 346 | + $response->assertInertiaHas('example.nested', $resourceB); |
| 347 | + } |
| 348 | + |
281 | 349 | public function test_the_inertia_page_has_all_the_given_props() |
282 | 350 | { |
283 | 351 | Model::unguard(); |
|
0 commit comments