本文主要是介绍FGD · jest 让你的代码库更有保障,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
FGD
(FE GitHub Daily),前端 GitHub Daily, 由公众号素燕组织,每天分享一个前端实用的库,旨在拓宽技术视野,为业务快速找到低成本的解决方案。
推荐理由
平时写业务的时候很少接触到自动化测试,但是像 vue、react 这样的代码库,完全由世界上不同的人维护着,如何能够保证别人提交的代码不影响已有的功能呢?
这不得不借助自动化测试。
jest 是一个令人愉快的 JavaScript 测试框架,专注于简洁明快。像 Babel、 TypeScript、 Node、 React、 Angular、 Vue 这样的知名框架都在使用它。
假如有下面的代码要测试:
function sum(a, b) {return a + b;
}
module.exports = sum;
可以使用 jest 进行这样测试:
const sum = require('./sum');test('adds 1 + 2 to equal 3', () => {expect(sum(1, 2)).toBe(3);
});
在 package.json 文件中写入:
{"scripts": {"test": "jest"}
}
运行测试:
PASS ./sum.test.js
✓ adds 1 + 2 to equal 3 (5ms)
还有一点需要强调一下,通过 测试用例可以更全面掌握开源框架的核心思想,也能够掌握框架如何使用。
GitHub 指数
???????????? Developer Ready: A comprehensive JavaScript testing solution. Works out of the box for most JavaScript projects.
???????? Instant Feedback: Fast, interactive watch mode only runs test files related to changed files.
???? Snapshot Testing: Capture snapshots of large objects to simplify testing and to analyze how they change over time.
Star 数 32.5k
https://github.com/facebook/jest
长按关注
素燕《前端小课》
帮助 10W 人入门并进阶前端
这篇关于FGD · jest 让你的代码库更有保障的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!