From 1cfbe6605fd6aceeaf3e5fc54238deb88481df94 Mon Sep 17 00:00:00 2001 From: neknalb Date: Tue, 18 Feb 2025 09:16:16 +0100 Subject: [PATCH 1/2] Update setup.mdx As I found out with my SvelteKit 5 project, we need to add `"types": ["@testing-library/jest-dom"]` to the `compilerOptions` in the project's `tsconfig.json`. Otherwise my VSCode complains that it can't find e.g. `toBeInTheDocument` (Property 'toBeInTheDocument' does not exist on type 'Assertion'.ts(2339)). I'm no TypeScript Pro, so feel free to reword what I wrote. :-) --- docs/svelte-testing-library/setup.mdx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/svelte-testing-library/setup.mdx b/docs/svelte-testing-library/setup.mdx index 2e0d8de9e..6f6f19f2f 100644 --- a/docs/svelte-testing-library/setup.mdx +++ b/docs/svelte-testing-library/setup.mdx @@ -138,6 +138,18 @@ runner that's ESM compatible. [resolve-conditions]: https://vitejs.dev/config/shared-options.html#resolve-conditions +### TypeScript + +If you use TypeScript and want to use [`@testing-library/jest-dom`][@testing-library/jest-dom] you need to tell the TypeScript compiler about [`@testing-library/jest-dom`][@testing-library/jest-dom] by adding it in your `tsconfig.json` to the `compilerOptions`. + +```json title="package.json" +{ + "compilerOptions": { + "types": ["@testing-library/jest-dom"], + } +} +``` + ## Jest [`@testing-library/svelte`][@testing-library/svelte] is ESM-only, which means From 03563de7874c21da4e343350da5b52df1a223f76 Mon Sep 17 00:00:00 2001 From: neknalb Date: Mon, 24 Feb 2025 22:54:35 +0100 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> --- docs/svelte-testing-library/setup.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/svelte-testing-library/setup.mdx b/docs/svelte-testing-library/setup.mdx index 6f6f19f2f..849335f21 100644 --- a/docs/svelte-testing-library/setup.mdx +++ b/docs/svelte-testing-library/setup.mdx @@ -140,9 +140,9 @@ runner that's ESM compatible. ### TypeScript -If you use TypeScript and want to use [`@testing-library/jest-dom`][@testing-library/jest-dom] you need to tell the TypeScript compiler about [`@testing-library/jest-dom`][@testing-library/jest-dom] by adding it in your `tsconfig.json` to the `compilerOptions`. +Include [`@testing-library/jest-dom`][@testing-library/jest-dom] to the TypeScript `types` to make the TypeScript compiler aware about the [`@testing-library/jest-dom`][@testing-library/jest-dom] matchers. -```json title="package.json" +```json title="tsconfig.json" { "compilerOptions": { "types": ["@testing-library/jest-dom"],