react typescript jest config (一)
1. initialize project
create a folder project
Now we’ll turn this folder into an npm package.
npm init -y
This creates a package.json file with default values.
2. Install react typescript dependencies
First ensure Webpack is installed.
npm i webpack webpack-cli webpack-merge html-webpack-plugin webpack-dev-server -D
Webpack is a tool that will bundle your code and optionally all of its dependencies into a single .js file.
Let’s now add React and React-DOM, along with their declaration files, as dependencies to your package.json file:
npm i react react-dom
npm i @types/react @types/react-dom -D
That @types/ prefix means that we also want to get the declaration files for React and React-DOM. Usually when you import a path like "react", it will look inside of the react package itself; however, not all packages include declaration files, so TypeScript also looks in the @types/react package as well. You’ll see that we won’t even have to think about this later on.
Next, we’ll add development-time dependencies on the ts-loader and source-map-loader.
npm i typescript ts-loader source-map-loader -D
or
npm i awesome-typescript-loader source-map-loader -D
Both of these dependencies will let TypeScript and webpack play well together. ts-loader helps Webpack compile your TypeScript code using the TypeScript’s standard configuration file named tsconfig.json. source-map-loader uses any sourcemap outputs from TypeScript to inform webpack when generating its own sourcemaps. This will allow you to debug your final output file as if you were debugging your original TypeScript source code.
Please note that ts-loader is not the only loader for typescript. You could instead use awesome-typescript-loader
Read about the differences between them:
https://github.com/s-panferov/awesome-typescript-loader#differences-between-ts-loader
Notice that we installed TypeScript as a development dependency. We could also have linked TypeScript to a global copy with npm link typescript, but this is a less common scenario.
3. Install jest enzyme dependencies
1、install jest dependencies
npm i jest @types/jest ts-jest -D
2、 install enzyme dependencies
npm i enzyme enzyme-adapter-react-16 jest-enzyme enzyme-to-json -D
npm i @types/enzyme @types/enzyme-adapter-react-16 -D
4. install another compiler for typescript use babel dependencies
install babel loader
npm i @babel/core @babel/preset-env @babel/preset-react @babel/preset-typescript -D
npm i babel-loader babel-plugin-import -D
config babel
module.exports={
presets: [
"env",
"react",
"typascript"
],
plugins: [
["lodash"],
["import", {libraryName: "antd", style: true}]
]
}
use babel loader instaed of ts-loader
react typescript jest config (一)的更多相关文章
- react: typescript jest && enzyme
Install Jest 1.install jest dependencies jest @types/jest ts-jest -D 2.jest.config.js module.exports ...
- react 单元测试 (jest+enzyme)
为什么要做单元测试 作为一个前端工程师,我是很想去谢单元测试的,因为每天的需求很多,还要去编写测试代码,感觉时间都不够用了. 不过最近开发了一个比较复杂的项目,让我感觉一旦项目大了.复杂了,而且还是多 ...
- 【每天学一点-04】使用脚手架搭建 React+TypeScript+umi.js+Antd 项目
一.使用脚手架搭建项目框架 1.首先使用脚手架搭建React项目(React+TypeScript+Umi.js) 在控制台输入命令:yarn create @umijs/umi-app 2.引入An ...
- react + typescript 学习
react,前端三大框架之一,也是非常受开发者追捧的一门技术.而 typescript 是 javascript 的超集,主要特点是对 类型 的检查.二者的结合必然是趋势,不,已经是趋势了.react ...
- React + Typescript领域初学者的常见问题和技巧
React + Typescript领域初学者的常见问题和技巧 创建一个联合类型的常量 Key const NAME = { HOGE: "hoge", FUGA: "f ...
- 前端自动化测试 —— TDD环境配置(React+TypeScript)
欢迎讨论与指导:) 前言 TDD -- Test-Drive Development是测试驱动开发的意思,是敏捷开发中的一项核心实践和技术,也是一种测试方法论.TDD的原理是在开发功能代码之前,先编写 ...
- React & TypeScript
之前看了一下 TypeScript 的知识,但是一直没有上手,最近开始结合 React 和 TypeScript 一起尝试了一下,感受还是很好的,所以写一下笔记. 环境配置没有参考其他东西,就是看了下 ...
- react: typescript project initialize
Initialize the project create a folder project Now we’ll turn this folder into an npm package. npm i ...
- 使用react搭建组件库:react+typescript+storybook
前期准备 1. 初始化项目 npx create-react-app react-components --template typescript 2. 安装依赖 使用哪种打包方案:webpack/r ...
随机推荐
- 面试都在问的微服务、服务治理、RPC、下一代微服务框架... 一文带你彻底搞懂!
文章每周持续更新,「三连」让更多人看到是对我最大的肯定.可以微信搜索公众号「 后端技术学堂 」第一时间阅读(一般比博客早更新一到两篇) 单体式应用程序 与微服务相对的另一个概念是传统的单体式应用程序( ...
- yum,rpm等失效,使用系统安装包ISO文件降级程序恢复系统
linux平台:REHL6.7 故障原因:由于不小心使用命令yum update nss误升级了工作平台中nss系列工具包导致系统中yum 和 rpm命令执行都报错. 由于yum rpm命令都不好用使 ...
- Python Tkinter Grid布局管理器详解
Grid(网格)布局管理器会将控件放置到一个二维的表格里.主控件被分割成一系列的行和列,表格中的每个单元(cell)都可以放置一个控件. 注意:不要试图在一个主窗口中混合使用pack和grid (1) ...
- Kubernetes实战总结 - Prometheus部署
什么是普罗米修斯? Prometheus是最初在SoundCloud上构建的开源系统监视和警报工具包 . 自2012年成立以来,许多公司和组织都采用了Prometheus,该项目拥有非常活跃的开发人员 ...
- Light of future-测试总结
目录 1.描述项目的测试工作安排 2.测试工具选择和运用 3.测试用例文档pdf的github链接地址 4.测试体会 5.项目测试评述 发布界面 后台CRUD 归属班级 →2019秋福大软件工程实践Z ...
- centos8系统下docker安装jenkins
前提是已经安装好docker 1.下载jenkins(最新版本) docker pull jenkins/jenkins 2.创建用于存放jenkins的文件夹 mkdir /home/var/jen ...
- 在.NET Core中检查证书的到期日期
在 NUnit 测试中,我需要检查证书的有效期. 下面的代码片段可用于使用自定义证书验证回调检查任何证书属性. 所有你需要做的就是在回调中读取你感兴趣的属性,这样你就可以在之后检查它们. DateTi ...
- PTA数据结构与算法题目集(中文) 7-34
PTA数据结构与算法题目集(中文) 7-34 7-34 任务调度的合理性 (25 分) 假定一个工程项目由一组子任务构成,子任务之间有的可以并行执行,有的必须在完成了其它一些子任务后才能执行.“ ...
- redis持久化(RDB、AOF、混合持久化)
redis持久化(RDB.AOF.混合持久化) 1. RDB快照(snapshot) 在默认情况下, Redis 将内存数据库快照保存在名字为 dump.rdb 的二进制文件中. 你可以对 Redis ...
- Shell:Day02.笔记
重定向和管道符:1.重定向 程序 = 指令 + 数据 命令 变量 在程序中,数据如何输入?有如何输出? 数据输入:键盘 -- 标准输入,但是并不是唯一输入方式: --std ...