Submitting forms using spies
In this section, you’ll hand-craft a reusable spy function and adjust your tests to get them back into AAA order.
Here’s a reminder of how one of those tests looked, from the CustomerForm test suite. It’s complicated by the fact it’s wrapped in a test generator, but you can ignore that bit for now—it’s the test content that’s important:
const itSubmitsExistingValue = (fieldName, value) =>
it("saves existing value when submitted", () => {
expect.hasAssertions();
const customer = { [fieldName]: value };
render(
<CustomerForm
original={customer}
onSubmit={(props) =>
expect(props[fieldName]).toEqual(value)
...