-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed
Description
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 new mount()
function.
The issue is the same with happy-dom
.
Reproduction
Simple reproduction available here: Stackblitz
Versions:
Example:
// @vitest-environment jsdom
import { expect, test } from 'vitest';
import Hello from '../src/Hello.svelte';
import { mount } from 'svelte';
test('instantiate component', () => {
const target = document.createElement('div');
document.body.appendChild(target);
mount(Hello, {
target,
});
expect(target.innerHTML).toContain('Hello');
});
FAIL test/mount.test.ts > instantiate component
Svelte error: lifecycle_function_unavailable
`mount(...)` is not available on the server
❯ Module.lifecycle_function_unavailable node_modules/svelte/src/internal/server/errors.js:9:16
7| */
8| export function lifecycle_function_unavailable(name) {
9| const error = new Error(`${"lifecycle_function_unavailable"}\n${`\`${name}(...)\` is not available on the server`}`);
| ^
10|
11| error.name = 'Svelte error';
❯ Module.mount node_modules/svelte/src/index-server.js:29:24
❯ eval test/mount.test.ts:11:3
Logs
No response
System Info
System:
OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
CPU: (24) x64 13th Gen Intel(R) Core(TM) i7-13700K
Memory: 12.33 GB / 15.49 GB
Container: Yes
Shell: 3.6.4 - /usr/bin/fish
Binaries:
Node: 20.11.1 - /usr/bin/node
Yarn: 1.22.19 - /usr/bin/yarn
npm: 10.2.4 - /usr/bin/npm
bun: 1.0.30 - ~/.bun/bin/bun
npmPackages:
rollup: ^3.7.0 => 3.20.0
Severity
blocking an upgrade
ValentinVignal
Metadata
Metadata
Assignees
Labels
No labels