Enzyme 迁移到 React Testing Library

原名:react18-enzyme-to-rtl

把 React 旧 Enzyme 测试转换为更贴近用户行为的 Testing Library 测试。

中文 Skills 技能说明

适合 React 18 升级或测试体系现代化。先保留原测试意图,再替换 shallow、mount 和内部实现断言;迁移后运行完整测试,不能只追求语法对应。

上游能力依据

上游原始适用说明:Provides exact Enzyme → React Testing Library migration patterns for React 18 upgrades. Use this skill whenever Enzyme tests need to be rewritten - shallow, mount, wrapper.find(), wrapper.simulate(), wrapper.prop(), wrapper.state(), wrapper.instance(), Enzyme configure/Adapter calls, or any test file that imports from enzyme. This skill covers the full API mapping and the philosophy shift from implementation testing to behavior testing. Always read this skill before rewriting Enzyme tests - do not translate Enzyme APIs 1:1, that produces brittle RTL tests.

上游 SKILL.md 主要章节(保留原文标题):

使用边界

先复现问题并固定测试范围,再生成或执行测试。测试通过只能证明已覆盖的场景,不能代替生产环境验收。

作者、翻译与许可证

原作者
GitHub, Inc. 与 awesome-copilot contributors
中文翻译
CEOFans翻译
许可证
MIT
上游来源
https://github.com/github/awesome-copilot/tree/3f0bba475ec40b9680e1d0311b9caffeec5ad4c3/skills/react18-enzyme-to-rtl

适用范围

平台:linux、macos、windows;标签:测试与质量、Enzyme 迁移到 React Testing Library

安全提示

基础静态扫描不等于绝对安全。技能可能调用命令、浏览器、云服务或本地文件,请在最小权限环境中使用,高风险操作必须人工确认。

如发现侵权、许可证或安全问题,可在本页前台提交投诉,管理员复核后可立即下架。