-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Svelte 5: vitest
+ jsdom
error: mount(...) is not available on the server
#11394
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
Comments
You need to add a specific resolver in your vite config /// <reference types="vitest" />
// Configure Vitest (https://vitest.dev/config/)
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
-export default defineConfig({
+export default defineConfig(({ mode }) => ({
test: {
/* for example, use global to avoid globals imports (describe, test, expect): */
// globals: true,
},
+ resolve: {
+ conditions: mode === 'test' ? ['browser'] : [],
+ },
plugins: [svelte()],
-});
+})); this will instruct vite to use the browser resolution to import stuff which in turn will make https://stackblitz.com/edit/svelte-5-vitest-mount-jsdom-heemji?file=vite.config.ts |
That's exactly what I needed, thanks! |
allowing it to mount: sveltejs/svelte#11394 (comment)
Someone knows why this config was necessary in Svelte 4? The config you provided works, and know my component testing is working properly, but there is another issue that I cannot find a way to solve. I have a test about a service that must run in a non-browser environment, so I used the |
I had the same problem, I followed the docs and it works now 👍 import {defineConfig} from 'vitest/config'
import {svelte} from '@sveltejs/vite-plugin-svelte'
import {svelteTesting} from '@testing-library/svelte/vite'
export default defineConfig({
plugins: [svelte(), svelteTesting()],
test: {
environment: 'jsdom',
setupFiles: ['./vitest-setup.js'],
},
}) |
Describe the bug
When testing a component in the
jsdom
environment using Vitest, you get the following error:mount(...) is not available on the server
. This error occurs when you try to instantiate a component using the newmount()
function.The issue is the same with
happy-dom
.Reproduction
Simple reproduction available here: Stackblitz
Versions:
Example:
Logs
No response
System Info
Severity
blocking an upgrade
The text was updated successfully, but these errors were encountered: