-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
docs: Clarify how to run unit tests in a browser-like environment #14243
base: main
Are you sure you want to change the base?
Conversation
|
preview: https://svelte-dev-git-preview-svelte-14243-svelte.vercel.app/ this is an automated message |
see #14239 (comment) the use of jsdom should be limited |
Can you please explain in more details why using jsdom should be limited, and why it's not the right way? You made these assertions without explanations. Here's my reasoning for this PR: the docs already have a step to tell vitest to use the browser entry points, and having vitest use jsdom seems like a missed step rather than a new step. This is especially true because the docs have an example that doesn't work (using If your concern is with bringing the "browser version" of code of all packages into tests, the docs also already have a link to testing-library/svelte-testing-library#222 (comment) which should give people good pointers on how to separate those things. |
if you add See the example config i made here: https://github.com/dominikg/vitest-example-svelte5/blob/main/vitest.workspace.ts where there are 2 "vitest workspaces" for tests, one in a client environment with jsdom and svelte-testing-library, and the other a node environment without client addons. Only files with The template for adding vitest with |
Thank you! I understand better now the issue. I can do a bigger pass on this docs page to add this information, would that be ok, or is it a requirement to update the docs and |
Closes #14239.
The docs had some missing code when setting up vitest for testing in a browser-like environment, which this PR addresses. It also clarifies that this is needed for tests that use
$effect.root
.Given that a new svelte project (with vitest) created with the CLI doesn't change
vite.config.js
to include that browser-like environment config, it's easy to miss this extra config that is needed.