Replacing Behavior with a Side-By-Side Implementation
In the previous two chapters you built out a fully formed repository and an API for accessing it. Now it’s time to complete the story arc by updating both the SvelteKit loader and form actions to use the API instead of the repository.
It’s worth pointing out that this isn’t a necessary step: it would be perfectly acceptable to keep the SvelteKit server pieces pointing directly at the repository.
But reworking our existing code to point at the new API endpoints will introduce you to two ideas: first, that of a side-by-side implementation, which is a way to use tests to replace the existing code while ensuring the test suite remains on Green. The second is the use of a test double to shield the unit tests from SvelteKit. The test double takes the place of the framework code, avoiding a real network call out to the API – which wouldn’t work anyway since the API isn’t running within our...