# Demo地址

https://github.com/68wangxianming/front-end-algorithm

# 环境搭建

ES6、Jest、NPM、Git

# jest安装

https://jestjs.io/docs/zh-Hans/getting-started

# 安装

npm install --save-dev jest
npm install babel-jest babel-core@^7.0.0-bridge.0 @babel/core regenerator-runtime babel-preset-env
1
2

编辑package.json

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

编辑.babelrc

{
    "presets": ["env", "react"]
}
1
2
3

# 创建js文件

function sum(a, b) {
    return a + b;
}
export default sum;
1
2
3
4
import sum from './index'

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

# 启动测试

npm test
1