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

Switch to ESM Jest config in docs #42144

Merged
merged 3 commits into from
Mar 28, 2023
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
10 changes: 5 additions & 5 deletions docs/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,11 @@ To set up Jest, install `jest`, `jest-environment-jsdom`, `@testing-library/reac
npm install --save-dev jest jest-environment-jsdom @testing-library/react @testing-library/jest-dom
```

Create a `jest.config.js` file in your project's root directory and add the following:
Create a `jest.config.mjs` file in your project's root directory and add the following:

```jsx
// jest.config.js
const nextJest = require('next/jest')
// jest.config.mjs
import nextJest from 'next/jest.js'

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
Expand All @@ -317,15 +317,15 @@ const createJestConfig = nextJest({

// Add any custom config to be passed to Jest
/** @type {import('jest').Config} */
const customJestConfig = {
const config = {
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],

testEnvironment: 'jest-environment-jsdom',
}

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig)
export default createJestConfig(config)
```

Under the hood, `next/jest` is automatically configuring Jest for you, including:
Expand Down