npm install jest --save-dev
npm install babel-jest @babel/core @babel/preset-env regenerator-runtime -D
编辑package.json
{
"scripts": {
"test": "jest"
}
}
编辑 .babelrc
{
"presets": ["@babel/preset-env"]
}
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
- vscode