Skip to content

Commit 58c7dc7

Browse files
committed
Add test for new header error bag feature
1 parent 7191b01 commit 58c7dc7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/MiddlewareTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,24 @@ public function test_default_validation_errors_can_be_overwritten()
140140
]);
141141
}
142142

143+
public function test_validation_errors_are_scoped_to_error_bag_header()
144+
{
145+
Session::put('errors', (new ViewErrorBag())->put('default', new MessageBag([
146+
'name' => 'The name field is required.',
147+
'email' => 'Not a valid email address.',
148+
])));
149+
150+
Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () {
151+
$errors = Inertia::getShared('errors')();
152+
153+
$this->assertIsObject($errors);
154+
$this->assertSame('The name field is required.', $errors->example->name);
155+
$this->assertSame('Not a valid email address.', $errors->example->email);
156+
});
157+
158+
$this->withoutExceptionHandling()->get('/', ['X-Inertia-Error-Bag' => 'example']);
159+
}
160+
143161
public function test_middleware_can_change_the_root_view_via_a_property()
144162
{
145163
$this->prepareMockEndpoint(null, [], new class extends Middleware {

0 commit comments

Comments
 (0)