Skip to content
CommandImported

svelte-storybook-mock

Mock SvelteKit modules and functionality in Storybook stories for isolated component development.

Imported description, not reviewed yet

This item came from its original repository and was only scanned automatically; no editor has written an Arabic description for it yet. Read its content yourself before you rely on it. This page is not indexed by search engines until it is reviewed.

Download

Files: 1 · Size: 6.4 KB

Download the ZIP

The file carries the license of the original source.

Install

After downloading, run the command in a terminal. unzip asks before it replaces any file that is there.

  • For this project

    It goes in: .claude/commands/

    mkdir -p .claude/commands && unzip ~/Downloads/svelte-storybook-mock.zip -d .claude/commands

  • For your account on the whole machine

    It goes in: ~/.claude/commands/

    mkdir -p ~/.claude/commands && unzip ~/Downloads/svelte-storybook-mock.zip -d ~/.claude/commands

Instructions

/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:

    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:

    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:

    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:

    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:

    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:

    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)

Files

  • LICENSE1 KB
  • svelte-storybook-mock.md5.4 KB

Comments (0)

No comments yet. Be the first.

Sign in to comment. Commenting comes at level 1 (Member).

Report

Similar items

  • CommandImported

    accessibility-audit

    Audit web accessibility for WCAG compliance with automated axe-core tests, keyboard and screen reader checks, and remediation guidance

    MITFiles: 1

  • CommandImported

    component-scaffold

    Scaffold React and React Native components with TypeScript, tests, styles, and Storybook stories

    MITFiles: 1

  • CommandImported

    create-component

    Guided component creation with proper patterns

    MITFiles: 1

  • CommandImported

    create-plugin

    Guided end-to-end plugin creation workflow with component design, implementation, and validation

    Apache-2.0Files: 1

  • CommandImported

    gws-events-renew

    Google Workspace Events: Renew/reactivate Workspace Events subscriptions.

    MITFiles: 1