Skip to content

Commit 278170a

Browse files
authored
Merge pull request #63 from docimin/copilot/fix-62
Add basic test infrastructure with Jest and React Testing Library
2 parents c0b6281 + 580906f commit 278170a

File tree

7 files changed

+17498
-2
lines changed

7 files changed

+17498
-2
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ pnpm run dev
4444

4545
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
4646

47+
## Testing
48+
49+
This project includes Jest and React Testing Library for testing. To run tests:
50+
51+
```bash
52+
pnpm test
53+
```
54+
55+
To run tests in watch mode:
56+
57+
```bash
58+
pnpm run test:watch
59+
```
60+
61+
Tests are located in the `src/__tests__` directory.
62+
4763
## .env
4864

4965
Want to host the website yourself?

jest.config.mjs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import nextJest from 'next/jest.js'
2+
3+
const createJestConfig = nextJest({
4+
// Provide the path to your Next.js app to load next.config.js and .env files
5+
dir: './',
6+
})
7+
8+
// Add any custom config to be passed to Jest
9+
const customJestConfig = {
10+
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
11+
testEnvironment: 'jest-environment-jsdom',
12+
moduleNameMapper: {
13+
'^@/(.*)$': '<rootDir>/src/$1',
14+
},
15+
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'],
16+
collectCoverageFrom: [
17+
'src/**/*.{js,jsx,ts,tsx}',
18+
'!src/**/*.d.ts',
19+
],
20+
}
21+
22+
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
23+
export default createJestConfig(customJestConfig)

jest.setup.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Optional: configure or set up a testing framework before each test.
2+
// If you delete this file, remove `setupFilesAfterEnv` from `jest.config.js`
3+
4+
// Used for __tests__/testing-library.js
5+
// Learn more: https://github.com/testing-library/jest-dom
6+
import '@testing-library/jest-dom'

0 commit comments

Comments
 (0)