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 long类型转换易犯的错误

    记一个刷题过程中遇到的溢出问题. 在做这道题的时候遇到一个与 long 类型有关的溢出错误. 原始代码如下 class Solution { public int numberOfPairs(int[ ...

  2. 【开源】libinimini:适用于单片机的极简 ini 解析库

    介绍说明 最近自己基于 XR872 在做一个小作品练习练习,具备可以配置的功能,选择了使用 ini 作为配置文件.我调研了网上常见的 ini 解析库,几乎都涉及到了 fopen()/fgets().. ...

  3. 【学习笔记】C/C++ 设计模式 - 观察者模式

    前言 估计 2020 年写应用程序的机会比较多,之前一直在做嵌入式驱动程序和Android系统定制方面的工作,在应用程序方面积累的不是很多,因此迫切需要多学学应用编程这方面的知识. 之前在写小的应用程 ...

  4. sync/atomic 原子操作使用与解析

    目录 前言 1. 引入 2. sync.atomic 原子操作 2.1 什么是原子操作 2.2 各种 API 的作用 2.2.1 Store 操作 2.2.2 Load 操作 2.2.3 Add 操作 ...

  5. Grafana 系列文章(九):开源云原生日志解决方案 Loki 简介

    简介 Grafana Labs 简介 Grafana 是用于时序数据的事实上的仪表盘解决方案.它支持近百个数据源. Grafana Labs 想从一个仪表盘解决方案转变成一个可观察性 (observa ...

  6. drf-day3——drf整体流程、APIView执行流程及源码分析、Request对象源码分析、序列化器介绍和使用、反序列化的使用、反序列化的校验

    目录 一.drf 整体内容 二.APIView执行流程--源码分析(难,了解) 2.1 基于APIView+JsonResponse编写接口 2.2 基于APIView+Response 写接口 2. ...

  7. P30_全局配置 - window - 下拉刷新

    window 全局开启下拉刷新功能 概念:下拉刷新是移动端的专有名词,指的是通过手指在屏幕上的下拉滑动操作,从而重新加载页面数据的行为. 设置步骤:app.json -> window -> ...

  8. .NET Core Redis的简单使用

    1.Redis简介 Redis 是完全开源的,遵守 BSD 协议,是一个高性能的 key-value 数据库. 2.Redis主要特点 Redis支持数据的持久化 Redis支持多种数据结构 Redi ...

  9. Spring(Spring的读取外部资源- p 命名空间)

    Spring读取外部资源 实际开发中,数据库的资源一般会单独保存起来.一般会保存到后缀为properties的文件中,方便维护和修改,如果Spring加载资源,就需要在spring.xml中读取pro ...

  10. Technique to Read Source Code

    Technique to Read Source Code Excerpted from http://ruby-hacking-guide.github.io/intro.htm Any progr ...