Jest

安装Jest

npm install --save-dev jest

创建文件︰

sum.js

1
2
3
4
function sum(a, b) {
return a + b;
}
module.exports = sum;

sum.test.js

1
2
3
4
5
const sum = require('./sum');
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});

配置

package.json

1
2
3
4
5
{
"scripts": {
"test": "jest"
}
}

运行

yarn test

结果

1
2
PASS ./sum.test.js
✓ adds 1 + 2 to equal 3 (5ms)
---------------
Enjoy it ? Donate me !
欣赏此文?求鼓励,求支持!