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. Windows Server上部署IoTdb 集群

    本文是参考官方的 IoTDB 集群版(1.0.0)的安装及启动教程:https://iotdb.apache.org/zh/UserGuide/V1.0.x/Cluster/Cluster-Setup ...

  2. Coolify系列02-从0到1超详细手把手教你上手Coolify

    接着上集(Coolify系列01- 从0到1超详细手把手教你上手Heroku 和 Netlify 的开源替代方案 ),此时我们已经运行成功,如果没有成功,可以参考我的Coolify系列其他文章来解决问 ...

  3. 图文并茂strapi 4.5.5自定义搭建指南以及数据库字段名接口返回mapping分析

    strapi是什么? 基于Nodejs的开源免费CMS框架 为什么选择它? 基于nodejs,100%JavaScript,上手迅速 可轻松创建功能强大且可自定义的API 可以使用任何喜欢的数据库 先 ...

  4. 使用SQL获取当前周别,oracle日期处理

    使用SQL获取当前周别 select to_char(sysdate,'yyyyww') from dual  select to_char(to_date('20200611','yyyymmdd' ...

  5. 对象的变为私有方法不可改动 seal freeze

  6. SSM中PageHelper的使用方法

    SSM中PageHelper的使用方法 转载于for dream 第一步.导包(或者导入坐标) <!-- https://mvnrepository.com/artifact/com.githu ...

  7. java 进阶P-2.3+P-2.4

    封闭的访问属性 private 封装:把数据和对数据的操作放在一起. (所谓封装就是把数据和对这些数据的操作放在一个地方,通过这些操作把这些数据保护起来,别人不能直接接触到这些数据) 1 privat ...

  8. Node.js学习笔记----day04之学生信息管理系统

    认真学习,认真记录,每天都要有进步呀!!! 加油叭!!! 一.起步 项目结构 安装需要的包 初始化显示index.html index.html var express = require('expr ...

  9. redis-04配置文件

    1.daemonize no # By default Redis does not run as a daemon. Use 'yes' if youneed it.# Note that Redi ...

  10. 元数据库 information_schema.tables

    转  https://www.cnblogs.com/ssslinppp/p/6178636.html 1.information_schema数据库 对于mysql和Infobright等数据库,i ...