React 19 - Objects are not valid as a React child
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Da chiarire
- Stato di attività
- Tranquilla
- Stack tecnologico
- javascript, react, vite
- Ambito
- testing
Direzione di ricerca
Inizia da package.json e vitest.config.mjs, quindi esegui npm run test su button.test.tsx per riprodurre l’errore di rendering. Controlla come vengono risolte in questo pacchetto le versioni di React, React DOM, Vite e @testing-library/react. Il lavoro è completato quando superano entrambi il semplice test di div e il test di rendering di Button.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
@testing-library/reactversion: 16.3.0- Testing Framework and version: vitest 3.2.4
- DOM Environment: jsdom 26.1.0
Relevant code or config:
//package.json
{
"name": "@emg-hub/ui",
"version": "0.0.0",
"private": true,
"exports": {
"./*": "./src/*.tsx"
},
"scripts": {
"lint": "eslint . --max-warnings 0",
"generate:component": "turbo gen react-component",
"test": "vitest"
},
"devDependencies": {
"@emg-hub/eslint-config": "*",
"@emg-hub/typescript-config": "*",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.8.0",
"@testing-library/react": "^16.3.0",
"@testing-library/user-event": "^14.6.1",
"@types/node": "^24.3.0",
"@types/react": "19.1.12",
"@types/react-dom": "19.1.9",
"@vitejs/plugin-react": "^5.0.2",
"@vitest/coverage-v8": "^3.2.4",
"@vitest/ui": "^3.2.4",
"eslint": "^9.34.0",
"jsdom": "^26.1.0",
"typescript": "5.9.2",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^3.2.4"
},
"dependencies": {
"react": "^19.1.1",
"react-dom": "^19.1.1"
}
}
//vitest.config.mjs
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { configDefaults } from 'vitest/config'
export default defineConfig({
plugins: [react()],
test: {
globals: true,
environment: 'jsdom',
exclude: [...configDefaults.exclude, 'e2e/*'], // optional
coverage: {
provider: 'v8', // or 'c8'
reporter: ['text', 'json', 'html'],
exclude: ['vite.config.*', 'src/main.*', '**/*.d.ts', '**/__tests__/**'],
},
},
})
//button.tsx
import { ReactNode } from "react";
interface ButtonProps {
children: ReactNode;
className?: string;
appName: string;
}
export const Button = ({ children, className, appName }: ButtonProps) => {
return (
<button
className={className}
onClick={() => alert(`Hello from your ${appName} app!`)}
>
{children}
</button>
);
};
//button.test.tsx
import { render, screen, fireEvent } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { Button } from './button';
describe('Button', () => {
beforeEach(() => {
vi.clearAllMocks();
});
describe('rendering', () => {
it('renders simple div', () => {
render(<div>Click me</div>);
expect(screen.getByText('Click me')).toBeInTheDocument();
});
it('renders with children text', () => {
render(<Button appName="test">Click me</Button>);
expect(screen.getByRole('button', { name: 'Click me' })).toBeInTheDocument();
});
});
});
What you did:
Tried running simple test using npm run test
What happened:
I got the error "Objects are not valid as a React child (found: object with keys {$$typeof, type, key, props, _owner, _store}). If you meant to render a collection of children, use an array instead." even on the simple test 'renders simple div'
Problem description:
I can't seem to run any test on this React component, with React 19. I also tried using Jest but same issues. I followed a guide to setup my test config. It's a simple internal package in a turborepo arch. The issue is always on the render method of the @testing-library/react
Suggested solution
I don't have any. I saw a similar issue #1387 but it was for a NextJs project and the solution offered isn't possible for me.
- Lingua principale
- JavaScript
- Stelle
- 19.7k
- Fork
- 1.2k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di testing-library/react-testing-library
-
fireEvent.select does not wrap its automatic native focus in actForse già presa @sergioperezcheco l’ha presa 3 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
bug: calling configure() without reactStrictMode resets it to undefined, silently disabling strict modeForse di nuovo libera @suhailopensource l’ha presa 73 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
testing-library/react-testing-library#1466 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 30/100
testing-library/react-testing-library#1459 · 2 commenti ·
-
perf: optimize container lookup with early exitForse di nuovo libera @Ch-Abhinav-Chowdary l’ha presa 299 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 35/100
testing-library/react-testing-library#1430 · 1 commento ·
-
`fireEvent.mouseEnter` does not forward `relatedTarget` (relatedTarget is the window instead)Forse già presa @swarnim02 l’ha presa 317 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
Tutte le issue di testing-library/react-testing-library
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
capricorn86/happy-dom#2485 ·
I maintainer di solito rispondono entro 2 giorni
-
area:space-accuracy good first issue track:data
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
Sara-Managed-Projects/space-radar#904 ·
I maintainer di solito rispondono entro 1 giorno