The saga should perform all the same work as our existing doSave. That's what we'll build out in this section:
- In the same test file, add the following test to the saga describe block (the one named addCustomer, not the second reducer block you've just been working on). It doesn't look too different from anything we've seen before:
it('submits request to the fetch api', async () => {
const inputCustomer = { firstName: 'Ashley' };
dispatchRequest(inputCustomer);
expect(window.fetch).toHaveBeenCalledWith('/customers', {
body: JSON.stringify(inputCustomer),
method: 'POST',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/json' }
});
});
- We'll need to define the spy on window.fetch for this to work. Change...