使用react搭建组件库(三)——使用测试功能

create-react-app 脚手架已经内置了 Jest 测试功能,只需要在命令行中执行,则实时监听测试文件

npx jest 文件名 --watch
 
ReactTestUtils 可搭配你所选的测试框架,轻松实现 React 组件测试。http://zh-hans.reactjs.org/docs/test-utils.html
 
不过推荐使用的是  React Testing Library
 
 
create-react-app 脚手架的以下安装的依赖,已经把测试依赖加了进去
 
{
    "@testing-library/jest-dom":"^4.2.4",
    "@testing-library/react":"^9.3.2",
    "@testing-library/user-event":"^7.1.2",
    "react-scripts":"3.3.0" //在3.3.0以上
}
 
根据文档可以知道支持以下三种格式命名的文件:

__tests__ 文件夹下的 .js 文件
.test.js
.spec.js
posted @ 2020-04-06 18:08  小猪冒泡  阅读(365)  评论(0编辑  收藏  举报