Extracting Logic Out of the Framework
An important property of maintainable software is its testability. This is the idea that all parts of the application should be straightforward to test. More specifically, the design of the application code should make it easy to write automated unit tests.
In this chapter, we’ll look at one technique for improving testability: moving domain logic out of the framework and into plain JavaScript. Plain JavaScript code is simpler to test because there are no complex framework objects that interact with your code.
The following diagram shows how to think about a SvelteKit code base in this way.
Figure 9.1 – Keeping application code outside of framework components to aid testability
In Chapter 7, Tidying up Test Suites, we took a step toward moving the storage of birthday data items into a birthdayRepository
module. We’ll continue that process by pushing data validation out of the SvelteKit form...