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. Java基础学习笔记-Java数据类型转换-(~ ̄▽ ̄)~

    JAVA数据类型和JS数据类型转换不一样,因为它是强类型语言嘛 类型转换规则 不允许数值类型和布尔类型 转换 整型.实型.字符型数据可以混合运算 类型转换分类 自动类型转换-隐式转换 1.整数转换为小 ...

  2. 你知道CDN是干嘛的吗?

    theme: cyanosis 前言 几年前,我在浏览互联网时偶然发现了一个新的电子商务网站,注意到网站上的图片加载速度不快.我刷新了页面并重试了几次.终于,十秒钟后,我能够看到带有图像的渲染网页. ...

  3. vue学习笔记(一)---- vue指令(在vue中使用样式的方式)

    认真学习,认真记录,每天都要有进步呀!!! 加油叭!!! 一.在vue中使用样式的方式: 1. 直接传递一个数组,注意: 这里的 class 需要使用 v-bind 做数据绑定 <style&g ...

  4. 为什么 Linux 需要虚拟内存(转载)

    为什么 Linux 需要虚拟内存 原文链接: https://draveness.me/whys-the-design-os-virtual-memory/ 操作系统中的 CPU 和主内存(Main ...

  5. elasticsearch-head-master安装

    1 简介 elasticsearch-head是一款专门针对于elasticsearch的客户端工具,elasticsearch-head是一个基于node.js的前端工程 2 依赖 需要安装node ...

  6. Redis-05持久化

    1 Redis持久化 RDB(Redis DataBase) AOF(Append Only File) 2 RBD 2.1 基本说明 在指定的时间间隔内将内存中的数据集快照写入磁盘文件,它恢复时将快 ...

  7. EPICS Archiver Appliance的定制部署1

    https://blog.csdn.net/weixin_43767046/article/details/112116112 简单部署试了一下之后,又试了下Site specific install ...

  8. JZOJ 1389. 玩诈欺的小杉

    思路 考虑一个点要不要翻,如果它左边的点为 \(1\),那么它必须翻 所以我们可以从左往右一列一列地翻 先枚举第 \(0\) 列的状态 然后之后的列就确定了 判断一下最后一列是不是 \(0\) 就行了 ...

  9. ElasticSearch7.6入门

    笔记记录 B站狂神说Java的ElasticSearch课程:https://www.bilibili.com/video/BV17a4y1x7zq 一.ElasticSearch概述 官网:http ...

  10. 三年观察揭示TNF抑制剂持续改善强柱患者躯体功能的预测因子

    标签:强直性脊柱炎; TNF抑制剂; 躯体功能; 预测因子 一项为期3年的观察研究揭示TNF抑制剂持续改善强直性脊柱炎患者躯体功能的预测因子 电邮发布日期:2016年3月28日 文献出处: van W ...