-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request]: SvelteKit mocks #20999
Comments
@benmccann does SvelteKit's handling of In other words, if we create mocks for |
|
I was able to come up with a workaround so I can test my forms that have use:enhance. With the storybook-addon-manual-mocks addon, you can make a wrapper for the enhance function to be able to mock it.
$lib/form.js
Use the function as normal inside your svelte component and import the wrapper: $lib/Component.svelte
Now create the mocked enhance function. The mocked folder needs to be in the same parent folder as the wrapper.
Directory: It's a bit less than ideal needing to have a wrapper for the function, but at least I can run my tests without errors. |
Oh wow, that's great inspiration for how we could bake this in, in the future. great job on the addon @gebeto! |
Is there any update on this issue? The proposed workaround by @eugenepentland only works when |
Sveltekit recently did an update which fixes the disable_scroll_handling issue in storybook. I was interested in mocks just so this error would quietly fail, this might help you as well. |
this feature is needed to use components with superforms because it uses beforeNavigate inside
|
hi, generally like SB but this issue is starting to make it impossible to actually use it for tests. I've on occasion tried a variety of things over the past few months but can't get anything to ever work. Is there any way to currently test a component which calls or imports goto at any point of the lifetime of the component? |
If someone encounters this weird error when using superForms:
you have to mock the page store inside your story to fix this: export const Default: Story = {
parameters: {
sveltekit_experimental: {
stores: {
page: {},
},
},
},
}; |
Is your feature request related to a problem? Please describe
SvelteKit's
$app/navigation
and$app/forms
don't work today because they rely on the SvelteKit client singleton, which isn't initialized since there's no application and just individual components. We wouldn't really want to make them work anyway because we don't want to actually do navigations and so we should mock these components.Describe the solution you'd like
Implement a Vite plugin (probably in
sveltekit/src/plugins
) that overrides Kit'sgoto
, and either calls theaction()
fromaddon-actions
or sends an event over the channel.If we wanted to get real fancy we'd let users map URLs to stories, and then use that map when intercepting goto and friends, to navigate stories instead. Like:
Describe alternatives you've considered
Intercept all navigations, ignores them, and logs them to the Actions panel similar to the NextJS integration
Are you able to assist to bring the feature to reality?
I can advise from the SvelteKit side, but not implement. PRs would be very welcome!
Additional context
No response
The text was updated successfully, but these errors were encountered: