(一)基本配置和测试覆盖率生成
1. 单元测试 和 集成测试
单元测试:在软件最小可测试模块进行验证,在前端就是一个模块,也就是说 一个方法必须是自己一个模块,才可以进行单元测试,modules 导出
集成测试:在单元测试的基础上,按照设计要求,组装成一个子系统,进行测试。整个项目进行整体测试
2. jest 初始化配置
执行如下命令
npx jest --init
进行一些选项选择
在项目根目录下生成:jest.config.js 文件
/*
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/en/configuration.html
*/
module.exports = {
// All imported modules in your tests should be mocked automatically
// automock: false,
// Stop running tests after `n` failures
// bail: 0,
// The directory where Jest should store its cached dependency information
// cacheDirectory: "/private/var/folders/wb/sc40ddb97yg366j1fb9h6h1w0000gp/T/jest_dy",
// Automatically clear mock calls and instances between every test
// clearMocks: false,
// Indicates whether the coverage information should be collected while executing the test
// collectCoverage: false,
// An array of glob patterns indicating a set of files for which coverage information should be collected
// collectCoverageFrom: undefined,
// The directory where Jest should output its coverage files
coverageDirectory: "coverage",
// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "/node_modules/"
// ],
// Indicates which provider should be used to instrument