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