Writing tests for updating store values
The page route component is responsible for ensuring the birthdays that are passed into it are saved in the store.
Here’s the first test from the src/routes/birthdays/page.test.js
file, which uses birthdaysStore.subscribe
to set a storedBirthdays
value within the test. After rendering the component, it expects the storedBirthdays
value to contain the birthdays:
it('saves the loaded birthdays into the birthdays store', () => { let storedBirthdays; birthdaysStore.subscribe( (value) => (storedBirthdays = value) ); render(Page, { data: { birthdays } }); expect(storedBirthdays).toEqual(birthdays); });
A second test is then needed to ensure the store value is updated whenever the component prop changes. This test makes use of the $set
function on the returned component to update the props on the component:
it('updates the birthdays...