Updating the page form action to use the API
In the section, we will update the page form action to use the new POST
and PUT
methods on the API endpoints instead of the addNew
and replace
functions of the repository.
This will be done using the same side-by-side technique of the previous section, but this time it’s more involved. We still need tests to verify that the spy is called with the right parameters and that the return value is given. But now we also need to verify that errors are converted to SvelteKit form failures, since the form action has separate handling for errors.
Another important change here is that we will use two tests for checking the parameters passed to the fetch
call. This is a powerful technique when faced with complex arguments where there are clumps of arguments that have separate meanings.
In the case of fetch, the URL and the HTTP verb are one clump: we can have a single test that verifies, for example, that we’re calling the POST...