Skip to content

POST/PUT/DELETE visits with Inertia forms or links become GET requests in Capybara E2E testsΒ #271

@EmCousin

Description

@EmCousin

Hi there,

First of all, thanks for all the great work on Inertia and its Rails integration.

When writing E2E tests with Rspec and Capybara, I noticed that submitting an Inertia powered form or clicking on an Inertia powered link always sends a get request to the server, ignoring the verb.

Example with a form:

Take the following client-side rendered component:

import React from 'react'
import { useForm } from '@inertiajs/inertia-react'

const MyForm = () => {
  const { post, data, setData, processing, errors } = useForm({
    name: '',
    email: '',
  });

  const handleSubmit = (e) => {
    e.preventDefault();
    post('/my/endpoint');
  };

  return (
    <form onSubmit={handleSubmit}>
      <input type="text" name="name" value={data.name} onChange={e => setData('name', e.target.value)} />
      <button type="submit">Submit</button>
    </form>
  )
}
  • βœ… When submitting the form, a POST request is sent to the server.
  • πŸ”΄ But when submitting the form in a Capybara test, it sends a GET request

Example with a link:

Take the following component:

import React from 'react'
import { Link } from '@inertiajs/inertia-react'

const MyLink = () => <Link href="/my/endpoint" method="post">My Link</Link>

export default MyLink;
  • βœ… When clicking on the link, a POST request is sent to the server.
  • πŸ”΄ But when clicking on the link in a Capybara test, it sends a GET request

I've been able to reproduce this issue in a Rails 7.1.3 app with Inertia 2.2.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions