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

docs(svelte-testing-library): add Svelte 5 setup instructions for Jest #1401

Merged
merged 1 commit into from
Jun 25, 2024
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
29 changes: 28 additions & 1 deletion docs/svelte-testing-library/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ you must use Jest in [ESM mode][jest esm mode].
3. Configure Jest to use jsdom, transform Svelte files, and use your setup file

```js title="jest.config.js"
module.exports = {
export default {
transform: {
'^.+\\.svelte$': 'svelte-jester',
},
Expand All @@ -182,6 +182,33 @@ you must use Jest in [ESM mode][jest esm mode].
}
```

:::note

If you are using Svelte 5, you must use `svelte-jester@5` or later, and you
will need to make additional changes to your Jest configuration.

- Update `transform` to compile `.svelte.(js|ts)` modules
- Allow `@testing-library/svelte` to be transformed, even though it's in
`node_modules`

```diff title="jest.config.js"
export default {
transform: {
- '^.+\\.svelte$': 'svelte-jester',
+ '^.+\\.svelte(\\.(js|ts))?$': 'svelte-jester',
},
+ transformIgnorePatterns: [
+ '/node_modules/(?!@testing-library/svelte/)',
+ ],
moduleFileExtensions: ['js', 'svelte'],
extensionsToTreatAsEsm: ['.svelte'],
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'],
}
```

:::

4. Add the following to your `package.json`

```json title="package.json"
Expand Down