Writing tests for reading store values
There are at least two tests needed when reading the store value: first, for the initial value when the component loads, and second, when an update comes in.
Here’s an example of the first, which you’ll find in src/routes/birthdays/NextBirthday.test.js
. Notice how we import the birthdays
store with the name, birthdaysStore
, which makes it very clear in the test that the object imported is the store. The Arrange phase of the test then calls birthdayStore.set
to prime the store with its initial value before the component is mounted:
import { birthdays as birthdaysStore } from '../../stores/birthdays.js'; ... describe('NextBirthday', () => { it('displays a single birthday', () => { birthdaysStore.set([ createBirthday('Hercules', '2023-09-01') ]); ...