其他分享
首页 > 其他分享> > Jest - Configuring Jest

Jest - Configuring Jest

作者:互联网

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"
        }
      }
    ]
  ]
}

 

 

 

标签:Jest,Configuring,babel,JavaScript,jest,want,import
来源: https://www.cnblogs.com/ningxin/p/15907004.html