Drying up DOM queries
Why stop now when we're on a roll? There's loads more we can extract!
In test/CustomerForm.test.js, we also have definitions for form, field, and labelFor. As it turns out, these are exactly the same as our definitions in test/AppointmentForm.test.js, so that's a great signal that we should extract them.
Since they all refer to a container, we have the same problem as we had with fetchRequestBody. However, rather than solving it by passing in a container reference, let's solve it by adding these functions to the object returned by the createContainer call.
In addition, the field function refers to fields within the customer form, so let's modify that to work for any form before extracting the function out of the test ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access