快速入门 · Jest中文文档 | Jest中文网
1.下载:npm install --save-dev jest
2.创建
sum.js文件:function sum(a, b) {
return a + b;
}
module.exports = sum;3.创建
sum.test.js的文件const sum = require('./sum');
test('adds 1 + 2 to equal 3', () => {// 使用了
expect和toBe来检测两个值是否完全相同
expect(sum(1, 2)).toBe(3);
});4.
配置package.json{"scripts": {"test": "jest" }}
5.运行:
yarn test或者npm test,即可输出测试结果