Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/svelte-testing-library/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ with any testing framework and runner you're comfortable with.
```js
import '@testing-library/jest-dom';
```

5.3 Set up automatic imports (optional)

To import this automatically in _every_ test file, create a new file containing the import statement from the previous step, then add the file to the `setupFiles` array in the `vitest.config.ts` (in this case, the file is `vitest.include.jsdom.ts` in the project root)

```js
import { defineConfig } from 'vitest/config';
import { svelte } from '@sveltejs/vite-plugin-svelte';

export default defineConfig({
plugins: [svelte({ hot: !process.env.VITEST })],
test: {
include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
globals: true,
environment: 'jsdom',
setupFiles: [
'./vitest.include.jsdom.ts'
]
}
});

```

6. Create your component and a test file (checkout the rest of the docs to see how)
and run the following command to run the tests.
Expand Down