ts-jest使用

2020-10-17  本文已影响0人  antlove
  1. 环境准备
    package.json
{
  "name": "ts-jest",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "devDependencies": {
    "@types/jest": "^26.0.14",
    "@types/node": "^14.11.10",
    "jest": "^26.5.3",
    "ts-jest": "^26.4.1",
    "typescript": "3.9.7"
  }
}
  1. 创建 jest.config.js
yarn ts-jest config:init
  1. sum.ts
module.exports = function(a: number, b: number): number {
    return a + b;
}
  1. sum.test.ts
const sum = require('./sum');
test('sum', () => {
    expect(sum(1,2)).toBe(3);
});
  1. 执行测试
yarn jest
image.png
上一篇下一篇

猜你喜欢

热点阅读