Install Jest

1、install jest dependencies

jest @types/jest ts-jest -D

2、jest.config.js

module.exports = {
"roots": [
"<rootDir>/src"
],
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}

3、test jest

foo.ts

export const sum = (...args) => args.reduce((acc, val) => acc+val, 0)

foo.test.ts

import {sum } from "./foo";
test("basic", () => {expect(sum()).toBe(0)})
test("basic begin", () => {expect(sum(1,2,3)).toBe(6)})

Install Enzyme

1、install enzyme dependencies

enzyme @types/enzyme enzyme-to-json enzyme-adapter-react-16 @types/enzyme-adapter-react-16

2、configue enzyme setup-test.ts

import { configure } from 'enzyme';
import * as Adapter from 'enzyme-adapter-react-16'; configure({ adapter: new Adapter() });

3、update jest.config.js

module.exports = {
"roots": [
"<rootDir>/src"
],
"setupFileAfterEnv": ["<rootDir>/setup-test.ts"]
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
"snapshotSerializers": ["enzyme-to-json/serializer"],
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}

4、update tsconfig.js

"exclude": **/*.test.ts""

最新文章

  1. tensorflow 学习笔记
  2. c#图片输出
  3. VC_MFC水波纹控件,开源
  4. Liferay7 BPM门户开发之29: 核心kernel.util包下面的通用帮助类ParamUtil、GetterUtil使用
  5. ruby关于flip-flop理解上一个注意点
  6. *nix高手站点
  7. Maven创建工程项目如何下载所需要的jar包
  8. ZYKeyboardUtil 全自动处理键盘遮挡事件
  9. 使用 pm2 来守护 NoderCMS
  10. linux 文件类命令笔记
  11. 张高兴的 Xamarin.Forms 开发笔记:Android 快捷方式 Shortcut 应用
  12. HDFS的7个设计特点
  13. What?VS2019创建新项目居然没有.NET Core3.0的模板?Bug?
  14. Lock锁与Condition监视器(生产者与消费者)。
  15. SAP PA Document List
  16. Visual Studio 2015 key 许可证,下载地址
  17. Luogu P1896 [SCOI2005]互不侵犯
  18. Python中应用SQL及SQLAlchemy(一)
  19. 20190215面试-C#操作外设-多线程-shocket
  20. Fib的奇怪定理 : gcd(F[n],F[m])=F[gcd(n,m)]

热门文章

  1. Mybatis入门三
  2. 通过pip控制台查看已安装第三方库版本及最新版本
  3. CentOS7配置环境变量
  4. IDEA+Mybatis-generator代码生成工具
  5. 实验十一 MySQLl备份与恢复1
  6. Codeforces Global Round 7
  7. Java项目集成Redis
  8. js对象中in和hasOwnProperty()区别
  9. CentOS8中安装maven
  10. MFC之TreeCtrl遍历所有节点