React 19 - Objects are not valid as a React child
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 冷清
- 技术栈
- javascript, react, vite
- 领域
- testing
调研方向
从 package.json 和 vitest.config.mjs 开始,然后针对 button.test.tsx 运行 npm run test,以重现渲染失败。检查此 package 中 React、React DOM、Vite 和 @testing-library/react 的版本是如何解析的。简单的 div 测试和 Button 渲染测试都通过后,即表示完成。
由索引模型根据 Issue 内容生成。
描述
@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.
- 主要语言
- JavaScript
- 星标
- 19.7k
- 派生
- 1.2k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
testing-library/react-testing-library 的其他 Issue
-
fireEvent.select does not wrap its automatic native focus in act可能已有人在做 @sergioperezcheco 于 6 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
-
bug: calling configure() without reactStrictMode resets it to undefined, silently disabling strict mode可能重新可做 @suhailopensource 于 76 天前认领,目前没有进行中的 PR。 未关闭
难度 2/5 1-3 小时 新手友好度 35/100
testing-library/react-testing-library#1466 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 30/100
testing-library/react-testing-library#1459 · 2 条评论 ·
-
perf: optimize container lookup with early exit可能重新可做 @Ch-Abhinav-Chowdary 于 302 天前认领,目前没有进行中的 PR。 未关闭
难度 1/5 1 小时以内 新手友好度 35/100
testing-library/react-testing-library#1430 · 1 条评论 ·
-
`fireEvent.mouseEnter` does not forward `relatedTarget` (relatedTarget is the window instead)可能已有人在做 @swarnim02 于 319 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 55/100
查看 testing-library/react-testing-library 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 60/100
quarto-dev/quarto-cli#15042 ·
维护者通常 1 天内回复
-
OpenCode install copies the Pi harness directory (`.pi/`) into the OpenCode config root可能已有人在做 @gaurav0107 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
NaturalIntelligence/fast-xml-parser#890 · 1 条评论 ·
维护者通常 3 天内回复
-
Docs viewer: inverted grey colormap, Phantom CT window -20 to 35 HU, smoothing up to 40 mm可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭area: docs enhancement
难度 2/5 1-3 小时 新手友好度 64/100
PyTomography/PyTomography#331 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
pnpm/get.pnpm.io#68 ·