Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions docs/svelte-testing-library/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ runner that's ESM compatible.
your DOM library of choice and optionally configure your setup file from step
(2).

```js title="vitest.config.js"
```js title="vite.config.js"
import {defineConfig} from 'vitest/config'
import {svelte} from '@sveltejs/vite-plugin-svelte'
import {svelteTesting} from '@testing-library/svelte/vite'
Expand All @@ -63,6 +63,22 @@ runner that's ESM compatible.
})
```

Or, if you're using [SvelteKit][sveltekit]:

```js title="vite.config.js"
import {defineConfig} from 'vitest/config'
import {sveltekit} from '@sveltejs/kit/vite'
import {svelteTesting} from '@testing-library/svelte/vite'

export default defineConfig({
plugins: [sveltekit(), svelteTesting()],
test: {
environment: 'jsdom',
setupFiles: ['./vitest-setup.js'],
},
})
```

:::note

The `svelteTesting` plugin:
Expand Down Expand Up @@ -115,6 +131,7 @@ runner that's ESM compatible.
[happy-dom]: https://github.com/capricorn86/happy-dom
[@vitest/ui]: https://vitest.dev/guide/ui.html
[vitest dom]: https://vitest.dev/guide/environment.html
[sveltekit]: https://kit.svelte.dev/
[testing-library/svelte-testing-library#222]:
https://github.com/testing-library/svelte-testing-library/issues/222
[test-setup-files]: https://vitest.dev/config/#setupfiles
Expand Down Expand Up @@ -155,13 +172,13 @@ you must use Jest in [ESM mode][jest esm mode].

```js title="jest.config.js"
module.exports = {
"transform": {
"^.+\\.svelte$": "svelte-jester"
transform: {
'^.+\\.svelte$': 'svelte-jester',
},
"moduleFileExtensions": ["js", "svelte"],
"extensionsToTreatAsEsm": ["svelte"]
"testEnvironment": "jsdom",
"setupFilesAfterEnv": ["<rootDir>/jest-setup.js"]
moduleFileExtensions: ['js', 'svelte'],
extensionsToTreatAsEsm: ['.svelte'],
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'],
}
```

Expand Down