- 安装
npm install --save-dev jest
npm install babel-jest babel-core@^7.0.0-bridge.0 @babel/core regenerator-runtime babel-preset-env
编辑package.json
{
"scripts": {
"test": "jest"
}
}
编辑.babelrc
{
"presets": ["env", "react"]
}
- 创建js文件
function sum(a, b) {
return a + b;
}
export default sum;
import sum from './index'
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
- 启动测试
npm test
- 工具安装
- IDE:VSCode