Jest is a delightful JavaScript Testing Framework with a focus on simplicity. It works with projects using: BabelTypeScriptNodeReactAngularVue and more!

Install:

npm i jest -D

Setup:

package.json

 "scripts": {
"test": "jest"
},

By default, Jest only supports standard JavaScript syntax. Once you want to import a function, you have to use 'require'

Such as:

const {plus, subtract} = require('./calculator.js')

If you are using 'import', there is an error as below:

If you want to use 'import', you have to install the following dependencies:

    "@babel/core": "^7.17.4""@babel/preset-env": "^7.16.11"

Then we need to configure the .babelrc

{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}

Also if there is TypeScript In your project, you have to add the babel for typescript

npm i -D @babel/preset-typescript

.babelrc

{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
],
"@babel/preset-typescript"
]
}

Jest - Configuring Jest的更多相关文章

  1. [Web] How to Test React and MobX with Jest

    转载自: https://semaphoreci.com/community/tutorials/how-to-test-react-and-mobx-with-jest?utm_content=bu ...

  2. React Jest测试

    一. var jest = require('jest'); jest.dontMock('../CheckboxWithLabel.js'); describe('CheckboxWithLabel ...

  3. 【前端单元测试入门05】react的单元测试之jest

    jest jest是facebook推出的一款测试框架,集成了前面所讲的Mocha和chai,jsdom,sinon等功能. 安装 npm install --save-dev jest npm in ...

  4. 使用VSCode调试Jest

    0. 环境 Node版本:8.12.0 操作系统:windows10 1. 配置launch.json { "version": "0.2.0", " ...

  5. 搭建 Jest+ Enzyme 测试环境

    1.为什么要使用单元测试工具? 因为代码之间的相互调用关系,又希望测试过程单元相互独立,又能正常运行,这就需要我们对被测函数的依赖函数和环境进行mock,在测试数据输入.测试执行和测试结果检查方面存在 ...

  6. jest+vue-test-utils初步实践

    一.起步 1. jest Jest是 Facebook 的一套开源的 JavaScript 测试框架, 它自动集成了断言.JSDom.覆盖率报告等开发者所需要的所有测试工具,配置较少,对vue框架友好 ...

  7. [Testing] Config jest to test Javascript Application -- Part 3

    Run Jest Watch Mode by default locally with is-ci-cli In CI, we don’t want to start the tests in wat ...

  8. [Testing] Config jest to test Javascript Application -- Part 2

    Setup an afterEach Test Hook for all tests with Jest setupTestFrameworkScriptFile With our current t ...

  9. [Testing] Config jest to test Javascript Application -- Part 1

    Transpile Modules with Babel in Jest Tests Jest automatically loads and applies our babel configurat ...

  10. react 单元测试 (jest+enzyme)

    为什么要做单元测试 作为一个前端工程师,我是很想去谢单元测试的,因为每天的需求很多,还要去编写测试代码,感觉时间都不够用了. 不过最近开发了一个比较复杂的项目,让我感觉一旦项目大了.复杂了,而且还是多 ...

随机推荐

  1. GreenPlum批量授权(PG未测试)

    创建一个自定义function create or replace function grant_all_exec(schema_name varchar,select_or_insert varch ...

  2. ArcGIS工具 - 计算折点数量

    在GIS中,点构成线,线构成面,面构成体,维度增加,模型也加复杂.有时,我们需要统计线面等要素到底由多少个点构成,系统工具没有此功能,为源地理提供了三种解决方案. 方法一 折点转点 使用要素折点转点工 ...

  3. string 类的用法

    访问字符串中的元素 string 字符串也可以像C风格的字符串一样按照下标来访问其中的每一个字符.string 字符串的起始下标仍是从 0 开始.请看下面的代码: int main(){ string ...

  4. (补12月19)ORM查询优化、ORM事物操作、ORM常用字段参数、Ajax请求、Content-Type

    ORM查询优化.ORM事物操作.ORM常用字段参数.Ajax请求.Content-Type Q查询进阶操作 先产生一个对象 q_obj = Q() 修改默认对象 q_obj.connector = ' ...

  5. Java 进阶P-8.5+P-8.6

    抛出异常 异常的抛出与声明 如果你的函数可能抛出异常,就必须在函数头部加以声明 你可以声明并不会真的抛出得异常 什么能扔? 任何继承了Throw able类的对象 Exception类继承了Throw ...

  6. 创建型模式 - 原型模式Prototype

    孩子生来没娘的NT审核机制,又开始说我涉及到广告了,我涉及到什么广告了?我接着发. 学习而来,代码是自己敲的.也有些自己的理解在里边,有问题希望大家指出. 所属:创建型模式  原型模式 一般会和 工场 ...

  7. 使用 NineData 高效编写 SQL

    SQL 是 Structured Query Language 的缩写,中文翻译为"结构化查询语言".它是关系型数据库的标准语言,所有的关系型数据库管理系统(RDBMS),比如 M ...

  8. Flink1.15仅支持ZooKeeper3.5/3.6

    这是一个验证贴,因为社区文档是错误的. 先说结论 Flink1.15仅支持ZooKeeper3.5/3.6,不再支持3.4.FLINK-25146 Drop support for Zookeeper ...

  9. Linux三剑客日志处理系列

    三剑客日志处理系列 一.特殊符号 1.引号系列 必会 引号 含义 单引号 所见即所得,单引号里的内容会原封不动输出 双引号 和单引号类似,对双引号里面的特殊符号进行解析,对于{}花括号(通配符)没有解 ...

  10. *已解决 Javawe中servlet时出现空白页面,但又网站不报错的问题追溯(编码

    本次随笔内容为在学习过程中遇到问题不断排问题,不断查资料解决的过程,小菜鸟学习~相互交流(菜鸟互啄~) 遇到问题: Javawe中servlet时出现空白页面,但又网站不报错的问题追溯 解决: 1.t ...