JEST

Reference Link Office Doc

Jest是 Facebook 的一套开源的 JavaScript 测试框架, 它自动集成了断言、JSDom、覆盖率报告等开发者所需要的所有测试工具,是一款几乎零配置的测试框架

安装

yarn add --dev jest

create a sum.js file

function sum(a, b) {
  return a + b;
}
module.exports = sum;

Then, create a file named sum.test.js. This will contain our actual test:

const sum = require('./sum');

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});

Add the following section to your package.json:

{
  "scripts": {
    "test": "jest"
  }
}
    "test": "cross-env NODE_ENV=test jest",
    "test:watch": "yarn test --watch",
    "test:cov": "yarn test --coverage",
    "test:update": "yarn test -u",

One Reply to “JEST”

Leave a Reply

Your email address will not be published. Required fields are marked *