安装Jest
npm install --save-dev jest
创建文件︰
sum.js1234function sum(a, b) { return a + b;}module.exports = sum;
sum.test.js12345const sum = require('./sum');test('adds 1 + 2 to equal 3', () => { expect(sum(1, 2)).toBe(3);});
配置
package.json12345{ "scripts": { "test": "jest" }}
运行
yarn test
结果
|
|