Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

292
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda