Skip to content

Commit

Permalink
Vitest: Support for import aliases when using TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjoSolutions committed Nov 6, 2024
1 parent 7a6b20c commit fe6c378
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions docs/01-app/02-building-your-application/08-testing/01-vitest.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ npx create-next-app@latest --example with-vitest with-vitest-app

To manually set up Vitest, install `vitest` and the following packages as dev dependencies:

```bash filename="Terminal"
```bash filename="Terminal (for TypeScript)" switcher
npm install -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom vite-tsconfig-paths
# or
yarn add -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom vite-tsconfig-paths
# or
pnpm install -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom vite-tsconfig-paths
# or
bun add -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom vite-tsconfig-paths
```

```bash filename="Terminal (for JavaScript)" switcher
npm install -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom
# or
yarn add -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom
Expand All @@ -30,14 +40,15 @@ pnpm install -D vitest @vitejs/plugin-react jsdom @testing-library/react @testin
bun add -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom
```

Create a `vitest.config.ts|js` file in the root of your project, and add the following options:
Create a `vitest.config.mts|js` file in the root of your project, and add the following options:

```ts filename="vitest.config.ts" switcher
```ts filename="vitest.config.mts" switcher
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
plugins: [react()],
plugins: [tsconfigPaths(), react()],
test: {
environment: 'jsdom',
},
Expand Down

0 comments on commit fe6c378

Please sign in to comment.