Jest入门

快速入门 · 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,即可输出测试结果

你可能感兴趣的:(#,前端工程化,javascript,开发语言,ecmascript)