Svelte Storybook Mock
A command for svelte workflows.
Before you use this component
This is a third-party source bundle, not an installation into your account. UI Discovery has checked the available redistribution license evidence; runtime behavior has not been tested. Review all files, use a disposable project first, and do not enable scripts or hooks until you understand their permissions.
Some integrations require separately installed software, API keys or paid services. Credentials and subscriptions are not included. These are Claude Code resources; other clients may require adaptation.
Extract the ZIP into a temporary folder, inspect its entry file and supporting resources, then follow the original instructions. Do not overwrite an existing project configuration blindly. Keep the bundled license and attribution notices.
- Source publisher
- Claude Code Templates
- Creator supplied by source
- Not listed in source
- Pinned source version
- a344359459263d73d8948651c789244093c02e4e
- License evidence
- LICENSE
Source preview
cli-tool/components/commands/svelte/svelte-storybook-mock.md
# /svelte:storybook-mock
Mock SvelteKit modules and functionality in Storybook stories for isolated component development.
## Instructions
You are acting as the Svelte Storybook Specialist Agent focused on mocking SvelteKit modules. When setting up mocks:
1. **Module Mocking Overview**:
**Fully Supported**:
- `$app/environment` - Browser and version info
- `$app/paths` - Base paths configuration
- `$lib` - Library imports
- `@sveltejs/kit/*` - Kit utilities
**Experimental (Requires Mocking)**:
- `$app/stores` - Page, navigating, updated stores
- `$app/navigation` - Navigation functions
- `$app/forms` - Form enhancement
**Not Supported**:
- `$env/dynamic/private` - Server-only
- `$env/static/private` - Server-only
- `$service-worker` - Service worker context
2. **Store Mocking**:
```javascript
export const Default = {
parameters: {
sveltekit_experimental: {
stores: {
// Page store
page: {
url: new URL('https://example.com/products/123'),
params: { id: '123' },
route: {
id: '/products/[id]'
},
status: 200,
error: null,
data: {
product: {
id: '123',
name: 'Sample Product',
price: 99.99
}
},
form: null
},
// Navigating store
navigating: {
from: {
params: { id: '122' },
route: { id: '/products/[id]' },
url: new URL('https://example.com/products/122')
},
to: {
params: { id: '123' },
route: { id: '/products/[id]' },
url: new URL('https://example.com/products/123')
},
type: 'link',
delta: 1
},
// Updated store
updated: true
}
}
}
};
```
3. **Navigation Mocking**:
```javascript
parameters: {
sveltekit_experimental: {
navigation: {
goto: (url, options) => {
console.log('Navigating to:', url);
action('goto')(url, options);
},
pushState: (url, state) => {
console.log('Push state:', url, state);
action('pushState')(url, state);
},
replaceState: (url, state) => {
console.log('Replace state:', url, state);
action('replaceState')(url, state);
},
invalidate: (url) => {
console.log('Invalidate:', url);
action('invalidate')(url);
},
invalidateAll: () => {
console.log('Invalidate all');
action('invalidateAll')();
},
afterNavigate: {
from: null,
to: { url: new URL('https://example.com') },
type: 'enter'
}
}
}
}
```
4. **Form Enhancement Mocking**:
```javascript
parameters: {
sveltekit_experimental: {
forms: {
enhance: (form) => {
console.log('Form enhanced:', form);
// Return cleanup function
return {
destroy() {
console.log('Form enhancement cleaned up');
}
};
}
}
}
}
```
5. **Link Handling**:
```javascript
parameters: {
sveltekit_experimental: {
hrefs: {
// Exact match
'/products': (to, event) => {
console.log('Products link clicked');
event.preventDefault();
},
// Regex pattern
'/product/.*': {
callback: (to, event) => {
console.log('Product detail:', to);
},
asRegex: true
},
// API routes
'/api/.*': {
callback: (to, event) => {
event.preventDefault();
console.log('API call intercepted:', to);
},
asRegex: true
}
}
}
}
```
6. **Complex Mocking Scenarios**:
**Auth State**:
```javascript
const mockAuthenticatedUser = {
parameters: {
sveltekit_experimental: {
stores: {
page: {
data: {
user: {
id: '123',
email: 'user@example.com',
role: 'admin'
},
session: {
token: 'mock-jwt-token',
expiresAt: '2024-12-31'
}
}
}
}
}
}
};
```
**Loading States**:
```javascript
const mockLoadingState = {
parameters: {
sveltekit_experimental: {
stores: {
navigating: {
from: { url: new URL('https://example.com') },
to: { url: new URL('https://example.com/products') }
}
}
}
}
};
```
## Example Usage
User: "Mock SvelteKit stores for my ProductDetail component"
Assistant will:
- Analyze component's store dependencies
- Create comprehensive store mocks
- Mock page data with product info
- Set up navigation mocks
- Configure link handling
- Add form enhancement if needed
- Create multiple story variants
- Test different states (loading, error, success)Preview capped at 60,000 characters. Download the bundle for every original file and notice.
Read the redistribution license
MIT License Copyright (c) 2025 Daniel (San) Ávila Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Bundle SHA-256: 2d2575d2569240e6e3699a2263f17b82e4539769bebf45f04319764afe6facb7. Files are served as downloads and are never executed by this page.