Skip to content

Commit

Permalink
docs(svelte-testing-library): add Svelte 5 setup instructions for Jest (
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous committed Jun 25, 2024
1 parent b9ae554 commit 29df9b5
Showing 1 changed file with 28 additions and 1 deletion.
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

0 comments on commit 29df9b5

Please sign in to comment.