May 2019
Intermediate to advanced
496 pages
10h 38m
English
In this section, we'll use the fetch API to send customer data to our backend service. When the form is submitted, instead of directly calling the onSubmit prop, we'll send a POST HTTP request via the fetch API. If it returns a successful result, we'll call the onSubmit prop.
Add this next test in test/CustomerForm.test.js, right after the has a submit button test. This test is going to check that when we call fetch, we pass in the right arguments. In the Arrange phase of the test, we pass a new prop, fetch, to CustomerForm. This prop will eventually replace the onSubmit prop:
it('calls fetch with the right properties when submitting data', async () => { const fetchSpy ...Read now
Unlock full access