svelte-testing
Fix and create Svelte 5 tests with vitest-browser-svelte and Playwright. Use when fixing broken tests, debugging failures, writing unit/SSR/e2e tests, or working with vitest/Playwright.
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
Svelte Testing
Quick Start
// Client-side component test (.svelte.test.ts)
import { render } from 'vitest-browser-svelte';
import { expect } from 'vitest';
import Button from './button.svelte';
test('button click increments counter', async () => {
const { page } = render(Button);
const button = page.getByRole('button', { name: /click me/i });
await button.click();
await expect.element(button).toHaveTextContent('Clicked: 1');
});
Core Principles
-
Always use locators:
page.getBy*()methods, never containers -
Multiple elements: Use
.first(),.nth(),.last()to avoid strict mode violations -
Use untrack(): When accessing
$derivedvalues in tests - Real API objects: Test with FormData/Request, minimal mocking
Reference Files
- core-principles | foundation-first | client-examples
- server-ssr-examples | critical-patterns
- client-server-alignment | troubleshooting
Notes
- Never click SvelteKit form submit buttons - Always use
await expect.element() - Test files:
.svelte.test.ts(client),.ssr.test.ts(SSR),server.test.ts(API)
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-01-20
- Index updated
- 2026-02-04
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!