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.

⭐91stars🔀5forks📁View on GitHub🕐Updated Dec 31, 2025⬇️2downloads

When & Why to Use This Skill

This Claude skill streamlines the creation, debugging, and maintenance of Svelte 5 test suites using vitest-browser-svelte and Playwright. It empowers developers to implement robust unit, SSR, and E2E tests while adhering to modern best practices like locator-based selection, real API object usage, and proper reactivity handling.

Use Cases

  • Component Testing: Generate and refine client-side component tests using vitest-browser-svelte to ensure UI interactions and state changes work as expected.
  • End-to-End (E2E) Debugging: Identify and resolve failures in Playwright test suites by analyzing locators and fixing strict mode violations.
  • SSR and API Validation: Create comprehensive Server-Side Rendering tests and API endpoint validations using standard Request/Response objects for SvelteKit applications.
  • Reactivity Pattern Testing: Correctly test Svelte 5's values and state transitions using the untrack() pattern to avoid common reactivity pitfalls in test environments.
namesvelte-testing
descriptionFix 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 $derived values in tests
  • Real API objects: Test with FormData/Request, minimal mocking

Reference Files

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)