-
React>=16.9
-
TypeScript>=3.6.2
-
VS Code >=1.37.1
-
yarn >= 1.17.3
-
node >= 10.13.0
-
启动配置参考
.vscode/launch.json
-
设置断点,按 F5 即可调试.
- 安装 Prettier
- Pretter 的配置可以在 VS Code 的 Settings 里面配置.
yarn test
jest
默认运行上次提交之后有修改文件的相关测试.- 直接将测试代码写在
it()
全局函数或test()
函数块里就好了. 也可以用describe()
把这些 测试放在一个分组里. jest
自带了expect()
全局函数用作断言语句.- 简单的 Component 的测试参考
App.test.tsx
- 测试代码文件推荐跟源文件代码放在同一目录下. 支持
.test.ts
后缀.spec.ts
后缀,(说明: ts 可以,那么 ,tsx,js,jsx 也可以.),或者放在__test__
目录下. xit()
表示此测试暂时排序.fit()
表示暂时只运行此测试.focus it
yarn test -- --coverage
可以输出测试覆盖率报告.- 其他配置可以参考
jest
相关文档,然后在package.json
中配置.
test --env=node
速度比较快.
但是以下API 需要 jsdom
- 所有的浏览器特有的全局对象如
window
,document
ReactDOM.render()
TestUtils.renderIntoDocument()
- Enzyme 中的
mount()
不过下面的 API不需要 jsdom
TestUtils.createRenderer()
- Enzyme 中的
shallow()
- 快照测试也不需要
jsdom
最后可以安装 VS Code 的 Jest 插件
-
在 Chrome 中测试
yarn test:debug
- 打开 Chrome 输入
about:inspect
选择调试页面进程.
-
在 VS Code 中测试 执行 已经配置的 Debug CRA Tests 启动项即可. (先按 <C+Shift+D>)
This project was bootstrapped with Create React App.
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
Builds the app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
See the section about deployment for more information.
Note: this is a one-way operation. Once you eject
, you can’t go back!
If you aren’t satisfied with the build tool and configuration choices, you can eject
at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject
will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use eject
. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
You can learn more in the Create React App documentation.
To learn React, check out the React documentation.