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 ...
随机推荐
- HDU 4497 GCD and LCM 素因子分解+ gcd 和 lcm
题意: 给两个数,lll 和 ggg,为x , y , z,的最小公倍数和最大公约数,求出x , y , z 的值有多少种可能性 思路: 将x , y , z进行素因子分解 素因子的幂次 x a1 a ...
- [React]核心概念
本文是对React文档:核心概念部分的笔记,内容大致与文档相同. 文档链接 React哲学部分写的很好,务必要看 JSX JSX是JS的语法扩展,配合react使用,为JS和HTML的混写 JSX支持 ...
- dp例题03. 最大子矩阵和
题目Description: 给出一个矩阵, 求子矩阵(可以是其本身)数之和的最大值 Input: 第一行 为行数n和列数m (n≤500, m≤500) 接下来为一个n行m列的矩阵 (每 ...
- Java基础部分脑图
这两天事情多,Java摸鱼了,就抽空写了一个脑图聊以自慰,表示自己还是学了的 下面这些全会了,恭喜你,Java的基础你可以毕业了
- ajax前端传递对象给后端
前端操作如下即可:
- shell编写一个批量添加用户脚本
shell编写一个批量添加用户脚本 5.1问题 本例要求在虚拟机server0上创建/roo ...
- STM32CubeMX工程定时器配置
STM32CubeMX生成工程 选择自己的芯片型号 配置RCC寄存器时钟为外部晶振 单击芯片配置GPIO,选择输出方式,重命名标签等 进入时钟配置,本人使用的为8M外部晶振作为时钟源,PLL时钟源选择 ...
- Matlab入门(二)
数据类型 1.整形 有符号 1 字节整数 -27 - 27-1 int8() 有符号 2 字节整数 -215 - 215-1 int16() 有符号 4 字节整数 -231 - 231-1 int32 ...
- JAVA中Calendar 类的应用
转自:https://www.imooc.com/code/2340 侵删! Date 类最主要的作用就是获得当前时间,同时这个类里面也具有设置时间以及一些其他的功能,但是由于本身设计的问题,这些方法 ...
- MySQL学习之路2-数据库and数据表的基本操作
数据库基本操作 查看.选择数据库: show databases; use <databasename>; 创建数据库:create database <dbname> cha ...