Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

React 19 - Objects are not valid as a React child

オープン
#1,415 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
静か
技術スタック
javascript, react, vite
領域
testing

調査の方向性

package.json と vitest.config.mjs から始め、次に button.test.tsx に対して npm run test を実行して、レンダリングの失敗を再現します。このパッケージで React、React DOM、Vite、@testing-library/react のバージョンがどのように解決されるかを確認します。単純な div テストと Button のレンダリングテストの両方に合格すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

  • @testing-library/react version: 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.

主要言語
JavaScript
スター
19.7k
フォーク
1.2k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

testing-library/react-testing-library のほかの issue

testing-library/react-testing-library の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。