起步
jest --init
按照文档写了一个测试用例
// last.ts
function last(array: any[]) {
const length = array == null ? 0 : array.length
return length ? array[length - 1] : undefined
}
export default last
// __test__/last.test.ts
test("get array last element", () => {
expect(last([1, 2, 3])).toBe(3)
})
"scripts": {
"test": "jest",
"test:watch": "jest --coverage --watch",
"test:prod": "npm run lint && npm run test -- --no-cache"
},
npm run test
last.ts: Unexpected token, expected “,” (9:19)
然后开始配置babelyarn add --dev babel-jest @babel/core @babel/preset-env @babel/preset-typescript
// babel.config.js