node:test) and @testing-library/react. No Jest or Vitest — the test runner ships with Node.js itself.
File location
Tests live next to the component they cover, inside a__tests__ directory:
Test files use the
.mjs extension and ES module syntax. This matches the "type": "module" setting across the packages.Imports
| Import | Source |
|---|---|
assert | Node.js built-in — strict assertion mode |
describe, it | Node.js built-in node:test |
render, screen, fireEvent | @testing-library/react |
| Component under test | Relative path from __tests__/ |
Writing a test
Running tests
- Run once
- Unit tests only
- Watch mode
--experimental-test-coverage— generates coverage reports--experimental-test-module-mocks— enables module mocking (used to mocknext-intl)global-jsdom/register— provides a browser-like DOM environmenttsx— enables TypeScript imports without pre-compilationtests/setup.jsx— shared test setup (mocksnext-intl, configures testing-library)
What to test
Rendering
Rendering
Verify the component renders its content and key elements are accessible by role or text:
Props and variants
Props and variants
Confirm that different prop values produce the expected output:
User interactions
User interactions
Use
fireEvent or @testing-library/user-event to simulate clicks and input:Conditional rendering
Conditional rendering
Check that elements appear or are absent based on props:
Coverage
Coverage output is printed to the console after each run when using--experimental-test-coverage. Coverage for test files themselves is excluded via --test-coverage-exclude=**/*.test.*.
Related
Storybook
Visual component development and interactive stories.
Visual regression
Automated screenshot comparison with Chromatic.