Skip to content
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

Svelte 5: Context Issue #358

Closed
huntabyte opened this issue Apr 21, 2024 · 3 comments
Closed

Svelte 5: Context Issue #358

huntabyte opened this issue Apr 21, 2024 · 3 comments

Comments

@huntabyte
Copy link

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

@mcous
Copy link
Collaborator

mcous commented Apr 21, 2024

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

@huntabyte
Copy link
Author

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

@huntabyte
Copy link
Author

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

#222 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants