- esbuild-jest 相比 ts-jest 有更好的性能 也把ts-jest引入坑修复了
- esbuild-jest官方文档比较简洁 这里详细扩展下具体实例
资源
jest 官方文档:jestjs.io/docs/gettin…
esbuild jest 的github:github.com/aelbore/esb…
安装
yarn add -D jest @types/jest esbuild esbuild-jest
使用
package.json里配置好运行jest的内容
{
"scripts": {
"test": "jest"
}
}
新建jest.config.json
{
"transform": {
"^.+\\.(t|j)sx?$": "esbuild-jest"
}
}
函数文件sum.ts
export function sum(a: number, b: number): number {
return a + b
}
测试用例sum.test.ts
import sum from './sum'
test("add 1+1=2", () => {
expect(sum(1, 2)).toBe(3)
})
运行
yarn test
结果