Top level hooks support

#2 · closed · 2 comments

View on GitHub ↗

tommywalkie

Hi, first of all, thanks for the neat tool! Encountered `ReferenceError: describe is not defined` error while running a few tests inspired from the [Svelte Vitest example](https://github.com/nickbreaton/vitest-svelte-kit/blob/a2e7638003afe56322b149323dd96bf783445f08/examples/svelte-kit-demo-app/src/routes/about.test.ts) which is using top level hooks. ```ts import { cleanup, fireEvent, render, screen } from '@testing-library/svelte' import Hello from '../components/Hello.svelte' describe('Hello.svelte', () => { ``` When importing the accurate hooks, like in the `vitest-svelte-kit` example, tests work. Is it possible to support top level hooks ?

Comments

nickbreaton

Have you tried adding `globals: true` to a `vite.test` key in your svelte config? It would be placed here: https://github.com/nickbreaton/vitest-svelte-kit/blob/master/examples/svelte-kit-demo-app/svelte.config.js#L17 More information on the vitest docs: https://vitest.dev/config/#globals

tommywalkie

Well, I wasn't aware of this `globals` field. Stangely, I had working tests without needing this configuration in a classic Vite-Svelte setup, prior to migrating to SvelteKit. That said, this solved my issue while using `vitest-svelte-kit`, thank you!