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
Details
Usage
After installing, this skill will be available to your AI coding assistant.
Verify installation:
skills listSkill Instructions
name: svelte-testing
prettier-ignore
description: 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.
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)
More by spences10
View allResearch topics by verifying actual source content. Use when asked to research or study links and documentation.
Svelte runes guidance. Use for reactive state, props, effects, attachments, or migration. Covers $state, $derived, $effect, @attach. Prevents reactivity mistakes.
Svelte component patterns. Use for web components, component libraries (Bits UI, Ark UI, Melt UI), form patterns, or third-party integration.
Svelte deployment guidance. Use for adapters, Vite config, pnpm setup, library authoring, PWA, or production builds.