Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

290
Vistas
Laravel testing forms using Inertia

I am trying to find the best method for testing forms in Laravel. I'm using Inertia and Laravel Fortify for user accounts.

If I run what I'm trying to test in the web browser it works as expected, however, when I run the test I'm getting a 419 status response with the error being: CSRF token mismatch.

According to documentation for Inertia in Laravel it handles CSRF protection for us (which I guess is why running this manually in the browser works): https://inertiajs.com/csrf-protection

Here's my current code to test registering an user:

        $response = $this->get('/register')
            ->assertStatus(200);

        $response = $this->json('POST', '/register', [
            'name' => 'Example Name',
            'email' => 'example@example.com',
            'password' => 'password',
            'password_confirmation' => 'password'
        ]);

        $response->assertCreated();

I 'm also not sure if this is the correct way to test a POST request from a form, so if this is wrong please suggest a better method to write a test for this, or if it is better to use Laravel Dusk to perform this kind of test by simulating the user filling out the form.

To find out it was a CSRF issue I ran:

$response->dump();

in the test.

Any suggestions are much appreciated.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda