FEAT: Front-End Auto Testing

本文详细介绍如何使用Jest进行前端自动化测试,包括安装配置、编写测试用例、运行测试及覆盖率报告。通过具体示例,如sum.js文件的测试,展示了自动化测试在前端开发中的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

FEAT

FEAT: Front-End Auto Testing

前端自动化测试

jest

$ yarn add -D jest

# OR

$ npm i -D jest

https://jestjs.io/docs/en/getting-started

https://jestjs.io/docs/en/cli.html#coverage

https://jestjs.io/docs/en/mock-functions.html

https://jestjs.io/docs/en/using-matchers

demo

sum.js

const sum = (a = 0, b = 0) => {
    return a + b;
};

default export sum;

sum..test.js

import * as sum from("./sum");

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

package.json


{
    "scripts": {
        "test": "jest"
    }
}

shell


$ yarn test

# or

$ npm run test

740516-20190315193131855-1365718075.png

740516-20190315193117720-919383372.png

740516-20190315193109816-537674161.png

babel & jest

740516-20190318145748524-1697144623.png

expect

https://jestjs.io/docs/en/expect

// todo...

asynchronous

Promise & Async / Await

https://jestjs.io/docs/en/asynchronous

// todo...


TDD

Test-Drive Development 测试驱动开发

  1. React + TypeScript
  2. gulp + mocha + enzyme

740516-20190315220754445-1975944013.png

https://www.cnblogs.com/BestMePeng/p/react_ts_tdd.html
https://github.com/Penggggg/tdd-demo

...

转载于:https://www.cnblogs.com/xgqfrms/p/10539077.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值