This repository already uses Jest as its active test runner. Tests are colocated with the implementation and cover route components, shared UI, hooks, stores, and API helpers.
- Jest 30
next/jestintegrationjest-fixed-jsdomenvironment- React Testing Library
@testing-library/user-event@testing-library/jest-dom- MSW for request mocking where needed
jest-junitfor CI test result output
The main configuration lives in:
jest.config.tsjest.setup.tsjest.polyfills.ts
Important current config details:
collectCoverageisfalseby default in config, butpnpm test:coverageenables it from the CLI.- Coverage is collected from
app/,components/, andlib/. - Coverage thresholds are configured globally:
- branches: 60
- functions: 60
- lines: 70
- statements: 70
- Tests ignore
.next/,out/, andnode_modules/. - Path alias
@/is mapped to the repository root.
| Command | Use |
|---|---|
pnpm test |
Run the full Jest suite once |
pnpm test:watch |
Run Jest in watch mode |
pnpm test:coverage |
Generate coverage artifacts in coverage/ |
Examples:
pnpm test
pnpm test:watch
pnpm test:coverageTo run a single file:
pnpm test -- app/page.test.tsxTo filter by name:
pnpm test -- --testNamePattern="login"app/layout.test.tsxapp/page.test.tsxapp/providers.test.tsxapp/(tourist)/login/page.test.tsxapp/(user)/home/homepage.test.tsxapp/(user)/home/edit/page.test.tsx
Representative examples:
components/account/account-panel.test.tsxcomponents/animation/page-transition.test.tsxcomponents/auth/other-login-list.test.tsxcomponents/layout/top-bar.test.tsxcomponents/navigation/back-button.test.tsxcomponents/profile/bind-app-item.test.tsxcomponents/ui/button.test.tsx
hooks/use-fetch-profile.test.tsx
lib/form-helpers.test.tslib/message.test.tslib/token.test.tslib/utils.test.tslib/api/auth.test.tslib/api/client.test.tslib/api/oauth.test.tslib/api/user.test.tslib/constants/department.test.tslib/validations/profile.test.ts
store/use-auth-store.test.tsstore/use-panel-store.test.tsstore/use-user-list-store.test.tsstore/use-user-profile-store.test.ts
- Prefer colocated test files next to the source they cover.
- Use
*.test.tsor*.test.tsx. - Test visible behavior and state transitions instead of implementation internals.
- Use accessible queries first:
getByRole,getByLabelText,getByText. - Use
userEventfor interactions instead of lower-level DOM event helpers when possible.
next/jest is used so the Jest environment stays aligned with the Next.js project config.
jest.setup.ts is used for testing-library setup and shared mocks.
The repository includes an MSW setup and a NEXT_PUBLIC_API_MOCKING switch in application runtime. Tests that need network isolation can use the existing mock infrastructure rather than inventing a second mocking strategy.
pnpm test:coverage writes to coverage/ and produces:
- HTML report
lcov.info- JSON coverage
- Clover
- Cobertura
coverage/junit.xml
The CI workflow uploads:
coverage/junit.xmlastest-results- the entire
coverage/directory ascoverage-report
The current GitHub Actions flow runs:
pnpm test:coverage
pnpm buildinside .github/workflows/test.yml.
So if you change runtime behavior, you should expect both the Jest suite and the static export build to remain green.
For doc-only changes:
pnpm lintFor code changes:
pnpm test
pnpm lint
pnpm buildClear transient output if needed:
Remove-Item -Recurse -Force .next, coverage -ErrorAction SilentlyContinueCheck that:
tsconfig.jsonstill maps@/*jest.config.tsstill maps^@/(.*)$to<rootDir>/$1
Remember:
collectCoverageis off in base configpnpm test:coverageis the command that turns on coverage collection for normal workflows