Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
质量保证
|
39
Linting
Linting
并非用来寻找错误
,而是用来寻找
潜在
错误。
Linting
的一般含义是识别出可能的错
误或脆弱的结构,而这些脆弱结构会导致将来的错误。我们将使用
ESLint
来做
Linting
。
先从测试框架
Jest
开始(单元测试和集成测试都用它来运行)
。
5.6
 安装和配置
Jest
我曾有点儿犹豫本书应该选择哪个测试框架。虽然
Jest
最初是作为测试
React
应用的框架
出现的(现在仍是明智的选择),但
Jest
并不限于
React
,它是优秀的通用测试框架
。当
然,它也不是唯一的测试框架:
Mocha
、
Jasmine
、
Av
a
和
Tape
都是很好的选择。
最终我选择了
Jest
,因
为它提供了最好的综合体验(此观点得到了“
JavaScript
状况
2018
”
调查的支持,
Jest
的得分很高)
。尽管如此,因为测试框架存在大量相似之处,所以你可以
把学到的东西应用到最喜欢的那个上面。
要安装
Jest
,只需在项目目录下运行以下命令:
npm install --save-dev jest
(注意,这里用了
--save-dev
,这是在告诉
npm
它是开发依赖,应用正常运行并不需要它。
在
package.json
文件中,它被列在
devDependencies
而不是
dependencies
一节。)
接着,需要一种方法来运行
Jest
(可以运行项目中的任何测试)
。传统做法是在
package.
json
中配置一个脚本
。编辑
package.json
(版本库的
ch05/package.json
),修改
scripts
属性 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua
前端架构设计

前端架构设计

Micah Godbolt

Publisher Resources

ISBN: 9787115565099