-
SummaryExploring the testing docs for Svelte and the new experimental test addon (vitest Browser Mode) I have questions. I want to run some basic component tests in the browser and they need to run setup code to configure (or Mock) the Web Audio, local storage and other browser context (plus clean up after).
Thanks for any insights Additional informationNo response Create a reproductionNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
@JReinhold can you provide any pointers to above questions. I think my confusion stems from arriving in the middle of churn and docs in various places. My main question is do play functions in the svelte csf use testing libray abstractions as shown in https://storybook.js.org/docs/writing-tests/component-testing#write-a-component-test or the new viteest browser mode abstractions of playwrights locators etc as the latest experimental test addon docs indicate. I guess i can experiment but it's not clear what is supported going forward. Thanks. |
Beta Was this translation helpful? Give feedback.
-
I'll try to answer the best that I can.
Correct. When you import from https://storybook.js.org/docs/essentials/interactions#write-a-component-test
The You can see an example of the In Svelte CSF it would be something like this:
Depending on your use case, if you need the same mock across all stories in the file, you could also use
By default, when you run tests on stories with the Vitest integration, it will visit and render all of your stories, like a smoke-test. So it doesn't do anything other than rendering them, ensuring that rendering your stories works without errors. As soon as you add play-functions to your stories, they will be executed too.
Similar to the first answer, it uses Testing Library, it runs whatever you put into the play-function, and right now you can't put browser-level locators and assertions from Playwright. I assume you're talking about the
What you're looking for might be https://storybook.js.org/docs/writing-tests/component-testing#run-code-before-each-story-in-a-file If you have a real use case and you can share some code, maybe I can help out with that specific example to give you some ideas. |
Beta Was this translation helpful? Give feedback.
It's based on Storybook's abstractions in
@storybook/test
since our code can both run in Vitest and in the user's browser, whereas Vitest browser mode can only run in Vitest. We may revisit this in the future in some way, but for now it is the way it is. 😄 Hope that helps!