1.文档阅读 https://zh-hans.reactjs.org/docs/testing.html // react测试 -- 有些懵懵懂懂 https://reactjs.org/docs/test-utils.html // 官网提供的讲解与一些例子 https://jestjs.io/docs/en/getting-started // Jest 官网 http://wiki.c2.com/?ArrangeActAssert https://testing-library.com/docs/react-testing-library/intro/ // 测试用例代码库 -- 推荐 https://www.robinwieruch.de/react-testing-library // How to use React Testing Library Tutorial -- 推荐阅读 --- 后续添加翻译文本 https://jestjs.io/docs/en/tutorial-react // 有讲解到如何编写单元测试 https://github.com/facebook/jest/tree/master/examples/snapshot // Jest example https://github.com/facebook/jest/tree/master/examples // 多看学习下大神的实践 https://github.com/facebook/jest/blob/master/examples/snapshot/__tests__/link.react.test.js // 详细的代码例子可供参考 http://www.ruanyifeng.com/blog/2015/12/a-mocha-tutorial-of-examples.html // 可类比思考总结 视频资源 https://www.bilibili.com/video/BV1Pv411q7Hz/?spm_id_from=333.788.videocard.2 // 英文, 且没有字幕 中文视频/文档很少 2.整理输出 大概思路: 安装jest库进行react application的unit test, 也可以使用react-test-library进行react unit test的编写. 实践文档参考来源: https://zh-hans.reactjs.org/docs/testing-recipes.html 解读: 即可不使用react-testing-library, 直接是同jest进行编写unit test. 但是, 可能写起来会比较冗余, 所以又建议使用二次封装库. https://testing-library.com/docs/react-testing-library/intro 代码实践: 使用create-react-app脚手架创建react app, 并在其中实践react unit test的编写运行测试. https://github.com/ningxiaofa/react-unit-test-learning 后续补充 ... |