Porting tests from the form action
In this section, we’ll write out tests for the behavior that already exists in the birthdayRepository
module, together with ensuring that the functions return values for the form action to reuse.
The src/lib/server/birthdayRepository.js
file already contains the working code that you last touched on in Chapter 6, Editing Form Data. Here’s a reminder:
import { randomUUID } from 'crypto'; const db = new Map(); export const addNew = (item) => { const id = randomUUID(); db.set(id, { ...item, id }); }; export const getAll = () => Array.from(db.values()); export const clear = () => db.clear(); export const replace = (id, item) => db.set(id, { ...item, id }); export const has = (id) => db.has(id);
Most of this functionality is tested by way of the form action. We need to add tests and then double-check that they work.
Always requiring a failing test
When porting tests...