Back to Calendar

Day 9 Unit Testing

Even Santa checks his list twice — and now your Svelte code can get the same treatment! Unit testing in SvelteKit is powered by Vitest, making it easier than ever to ensure your components and logic are on the nice list.

The best part? Svelte's reactive classes work beautifully with tests. Since $state in classes behaves just like regular JavaScript, you can test your stores and logic without any special mocking magic. Create a .svelte.spec.ts file, write your assertions, and watch Vitest's gorgeous UI light up green like a Christmas tree!

Whether you're over-engineering a Christmas wish list with a binary search tree (hey, no judgment — it's very testable!) or just making sure your naughty-or-nice checker works correctly, testing keeps your codebase merry and bright.

Run npx sv add vitest to get started, then create your test files right alongside your components. When things go wrong, Vitest shows you exactly what failed — like having an elf quality control inspector for every function!

Read the docs · CLI setup guide

Credits

Illustrations by Icons 8:

  • Santa Hat
  • Santa sleigh
  • Cookie
  • Heart
  • Santa face
  • Present
  • ID
  • Snowflake
  • Snow Globe
  • Question Mark
  • Fairy Lights
  • Piggy Bank
  • Globe
  • Present #2

Illustrations by Elisabet Guba:

  • Clock

Icons by Obra Icons

Challenges by Svelte Ambassadors:

  • Stanislav Khromov
  • Willow (GHOST)
  • Paolo Ricciuti

Santa Tracker Data by NORAD via Danielle Vass