Skip to content

Latest commit

 

History

History
50 lines (39 loc) · 705 Bytes

README.md

File metadata and controls

50 lines (39 loc) · 705 Bytes
  1. 安装
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"]
}
  1. 创建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);
});
  1. 启动测试
npm test
  1. 工具安装