|
14 | 14 | use Inertia\LazyProp;
|
15 | 15 | use Inertia\Response;
|
16 | 16 | use Inertia\Tests\Stubs\FakeResource;
|
| 17 | +use Mockery; |
17 | 18 |
|
18 | 19 | class ResponseTest extends TestCase
|
19 | 20 | {
|
@@ -153,6 +154,29 @@ public function test_arrayable_prop_response(): void
|
153 | 154 | $this->assertSame('123', $page->version);
|
154 | 155 | }
|
155 | 156 |
|
| 157 | + public function test_promise_props_are_resolved(): void |
| 158 | + { |
| 159 | + $request = Request::create('/user/123', 'GET'); |
| 160 | + $request->headers->add(['X-Inertia' => 'true']); |
| 161 | + |
| 162 | + $user = (object) ['name' => 'Jonathan']; |
| 163 | + |
| 164 | + $promise = Mockery::mock('GuzzleHttp\Promise\PromiseInterface') |
| 165 | + ->shouldReceive('wait') |
| 166 | + ->andReturn($user) |
| 167 | + ->mock(); |
| 168 | + |
| 169 | + $response = new Response('User/Edit', ['user' => $promise], 'app', '123'); |
| 170 | + $response = $response->toResponse($request); |
| 171 | + $page = $response->getData(); |
| 172 | + |
| 173 | + $this->assertInstanceOf(JsonResponse::class, $response); |
| 174 | + $this->assertSame('User/Edit', $page->component); |
| 175 | + $this->assertSame('Jonathan', $page->props->user->name); |
| 176 | + $this->assertSame('/user/123', $page->url); |
| 177 | + $this->assertSame('123', $page->version); |
| 178 | + } |
| 179 | + |
156 | 180 | public function test_xhr_partial_response(): void
|
157 | 181 | {
|
158 | 182 | $request = Request::create('/user/123', 'GET');
|
|
0 commit comments