Enable JSX in vitest so React component tests can run
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 92/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- nextjs, react, typescript
- Domain
- frontend, testing-qa
Research direction
Start with frontend/vitest.config.ts and frontend/tsconfig.json; keep the Next.js JSX setting unchanged and add the automatic JSX transform only to Vitest's esbuild options. Use frontend/src/components/ui/Avatar.tsx as the first target, then add frontend/src/components/ui/Avatar.test.tsx covering the three rendering cases described in the issue. Run cd frontend && npx vitest run src/components/ui/Avatar.test.tsx and the full npx vitest run suite, and add the required fragment under changelog.d/.
Written by the indexing model from the issue text.
Description
What is wrong / what to do
@testing-library/react and jsdom are already in devDependencies, but no .tsx component test can run. tsconfig.json sets "jsx": "preserve" for Next.js, so vitest's esbuild emits classic React.createElement calls, and rendering any component fails with ReferenceError: React is not defined. Adding esbuild: { jsx: 'automatic' } to vitest.config.ts fixes this (tested locally). Add one small component test to prove it, for example for components/ui/Avatar.tsx.
Where in the code
frontend/vitest.config.ts:14-23— noesbuild/ JSX settingfrontend/tsconfig.json:14—"jsx": "preserve"(leave this alone; Next needs it)frontend/src/components/ui/Avatar.tsx:19-39— a simple first component to test
How to reproduce, or the test command
# test file starts with `// @vitest-environment jsdom`
cd frontend && npx vitest run src/components/ui/Avatar.test.tsx
Before the config change, render(<Avatar alt="nova" />) fails with ReferenceError: React is not defined.
Done when
-
vitest.config.tssetsesbuild: { jsx: 'automatic' }and nothing else in the config changes -
Avatar.test.tsxchecks that<Avatar alt="nova" />renders the initialN, that<Avatar />rendersU, and that<Avatar src="x.png" alt="a" />renders animgwithalt="a" - The existing suite still passes (
npx vitest run: 3 files / 20 tests today, plus the new one) - Tests added or updated, and the command above passes
- Changelog fragment in
changelog.d/
- Dominant language
- TypeScript
- Stars
- 0
- Forks
- 3
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 5
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from BeyondITL/contentine-create
-
good first issue level: 1 ui
Difficulty 2/5 1-3 hours Newbie friendliness 94/100
BeyondITL/contentine-create#58 ·
Maintainers usually reply within 1 day
-
Fix Enter on the marketplace Buy button opening details instead of buyingPossibly taken @developedbyBob claimed this 4 days ago. Openaccessibility claimed good first issue level: 1
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
BeyondITL/contentine-create#57 · 3 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
good first issue level: 1 testing
Difficulty 2/5 1-3 hours Newbie friendliness 94/100
BeyondITL/contentine-create#55 ·
Maintainers usually reply within 1 day
-
good first issue level: 1 testing
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
BeyondITL/contentine-create#54 ·
Maintainers usually reply within 1 day
-
engine good first issue level: 1
Difficulty 2/5 1-3 hours Newbie friendliness 94/100
BeyondITL/contentine-create#53 ·
Maintainers usually reply within 1 day
All issues in BeyondITL/contentine-create
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
appandflow/stim#5258 ·
Maintainers usually reply within 1 day
-
area/docs framework/hugo help wanted language/markdown
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 68/100
lingdojo/kana-dojo#33660 · 1 comment · 5 reactions ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
drizzle-team/drizzle-orm#6639 ·
Maintainers usually reply within 4 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100