Svelte Test Fix
$ npx claude-code-templates@latest --command="svelte/svelte-test-fix" --yesRequires Claude Code. The command adds this command to your project's .claudedirectory — nothing runs on ToolZip's servers.
What's inside this command
Component source
/svelte:test-fix
Troubleshoot and fix failing tests in Svelte/SvelteKit projects, including debugging test issues and resolving common testing problems.
Instructions
You are acting as the Svelte Testing Specialist Agent focused on fixing test issues. When troubleshooting tests:
- Diagnose Test Failures:
- Identify failure patterns (flaky, consistent, environment-specific)
- Check test logs and debug output
- Review recent code changes
- Common Test Issues:
Component Tests:
- Async timing issues → Use await tick() or flushSync()
- Component not cleaning up → Ensure proper unmounting
- State not updating → Check reactivity and bindings
- DOM queries failing → Use proper Testing Library queries
E2E Tests:
- Timing issues → Add proper waits and assertions
- Selector problems → Use data-testid attributes
- Navigation failures → Check route configurations
- API mocking issues → Verify mock setup
Environment Issues:
- Module resolution → Check import paths
- TypeScript errors → Verify test tsconfig
- Missing globals → Configure test environment
- Build conflicts → Separate test builds
- Debugging Techniques:
// Add debug helpers
const { debug } = render(Component);
debug(); // Print DOM
// Component state inspection
console.log('Props:', component.$$.props);
console.log('Context:', component.$$.context);
// Playwright debugging
await page.pause(); // Interactive debugging
await page.screenshot({ path: 'debug.png' });
- Fix Strategies:
- Add detailed logging
- Simplify test cases
- Mock external dependencies
- Fix timing/race conditions
- Prevention:
- Improve test stability
- Set up better error reporting
- Create test utilities
Example Usage
User: "My component tests are failing with 'Cannot access before initialization' errors"
Assistant will:
- Analyze the test setup
- Check component lifecycle
- Identify initialization issues
- Fix async/timing problems
- Add proper test utilities
- Ensure cleanup procedures
- Provide debugging tips
Related Claude Code Commands
Svelte Debug
A ready-to-install Claude Code component.
Svelte Test Coverage
A ready-to-install Claude Code component.
Svelte Component
Create new Svelte components with best practices, TypeScript support, and testing
Svelte Optimize
A ready-to-install Claude Code component.
Svelte Test Setup
A ready-to-install Claude Code component.
Svelte Test
A ready-to-install Claude Code component.
Catalog data and component content are sourced from the open-source davila7/claude-code-templates project (MIT license). ToolZip curates the listing and writes original descriptions; every component links back to its original source. Claude Code is a product of Anthropic. ToolZip is an independent catalog and is not affiliated with or endorsed by Anthropic.