Duplicating form validation behavior in the repository
In this section, we’ll continue porting across tests from the src/routes/birthdays/page.server.test.js
file, but now we’re going to duplicate the validation behavior within the form action itself.
Repetition as a design signal
The following steps contain a fair amount of repetition. First, the tests are very similar to tests you’ve already written in the form action. Second, the same checks are repeated for both the addNew
and replace
functions.
This kind of forced repetition (where you feel the pain of repeated work) can help you to figure out what (if any) shared logic you’d like to pull out.
Let’s begin:
- Start by filling in the
validation errors
nesteddescribe
block and the tests within it. I’m electing to copy two tests at once because these tests are very simple, and we already have a good idea of where we’re going to end up with the implementation:describe...