testing-library / testing-library-docs

docs site for @testing-library/*
https://testing-library.com
MIT License
451 stars 701 forks source link

Svelte Testing Library setup docs need additional info for SvelteKit #1388

Closed scottdotweb closed 4 months ago

scottdotweb commented 4 months ago

The setup docs for Svelte Testing Library say

Add vitest.config.js, or update your existing vite.config.js, with the svelte and svelteTesting Vite plugins.

And specifies the config as:

import {defineConfig} from 'vitest/config'
import {svelte} from '@sveltejs/vite-plugin-svelte'
import {svelteTesting} from '@testing-library/svelte/vite'

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

However when using SvelteKit you need to use its Vite plugin, which will already be in your config. So in that case it would look like this:

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'],
  },
})

I'd do a PR but I'm using all of this for the first time, so probably not the right person to go editing the docs right now.

MatanBobi commented 4 months ago

Thanks @scottdotjs :) Tagging @mcous which wrote that part.