testing-library/svelte-testing-library

Svelte 5: Context Issue

huntabyte opened this issue · 3 comments

I'm not 100% sure if this issue lies with Svelte or Svelte Testing Library, but when attempting to test any component that calls getContext / setContext, the tests crash with an error.

image

I've created a simple reproduction to demonstrate this:
Reproduction StackBlitz - just run pnpm test
Reproduction Repo

Your vite.config.js file is not configured to load Svelte's browser code. You can see that the stacktrace is pointing to Svelte's server code, instead: svelte/src/internal/server/context.js.

See the Vitest setup docs for proper Vitest setup to ensure Svelte's browser version is used

Ah, I see! I've added that conditional, yet it still seems to try to use the server/context.js 🤔

Using this method solved this issue for me, thank you!

#222 (comment)