小编mut*_*thu的帖子

如何在玩笑中跳过文件执行?

我正在使用 jest 进行集成测试,其中一个文件夹下有 20 个测试文件。我需要确保在运行测试时不需要执行该文件夹中的三个文件。我尝试使用testPathIgnorePatterns但它仅适用于文件夹而不适用于文件。怎么做?

笑话配置.js

/**
 * @file Jest Integration Test Configuration File
 */

module.exports = {
  roots: ['../../tests'],
  testRegex: '_*_integration.test.(js|ts|tsx)?$',
  globals: {
    'ts-jest': {
      tsconfig: 'tsconfig.json',
    },
  },
  moduleFileExtensions: ['ts', 'js'],
  transform: {
    '^.+\\.(ts|tsx)$': 'ts-jest',
  },
  testPathIgnorePatterns: ['tests/api/modules/m3/sample.test.ts'],
  testEnvironment: 'node',
  reporters: [
    'default',
    [
      '../../node_modules/jest-html-reporter',
      {
        pageTitle: 'Integration Test Report',
        outputPath: 'tests/reports/integration-test-report.html',
        includeFailureMsg: true,
      },
    ],
  ],
};

Run Code Online (Sandbox Code Playgroud)

javascript node.js jasmine jestjs

4
推荐指数
1
解决办法
7697
查看次数

如何在玩笑中使每个块描述动态化?

我正在使用 jest it.each 块来减少同一场景的测试用例的重复性,但我无法动态更新 it 块描述。怎么做?

测试用例示例

const testData = [
    {
      module: 'test_module',
      entityName: 'test_entity'
    },
    {
      module: 'test_module1',
      entityName: 'test_entity1'
    },
  ];

 it.each(testData)(`should perform get respose - ${entityName}`, async (entityDetails: any) => {
       
         const url = `${entityDetails.module}/${entityDetails.entityName}/all/`;
        // Executing
        const response = await request(server).get(url);
        // Verifying
        expect(response.status).toBe(200);

});

Run Code Online (Sandbox Code Playgroud)

在这个提供的示例中,我需要动态地将实体名称包含在块描述中。类似的事情
应该执行 get respose - test_entity
应该执行 get respose - test_entity1
如何实现这一点?

javascript node.js jasmine jestjs

3
推荐指数
1
解决办法
8051
查看次数

节点打字稿项目中的玩笑覆盖率始终返回空

我正在开发后端 Typescript 项目,我正在尝试获取单元测试用例的覆盖率报告。Jest 在终端和 html 报告中返回空的覆盖率报告,没有说明任何内容。我也尝试过,-- --coverage --watchAll=false但它也返回空文档。

包.json

"scripts":{
    "unit-test": "jest --config='./config/jest/jest_unit.config.js' --forceExit --detectOpenHandles",
}

Run Code Online (Sandbox Code Playgroud)

jest_unit.config.js

/**
 * @file Jest Unit Test Configuration File
 */
module.exports = {
  roots: ['../../tests'],
  testRegex: '.*_unit.test.(js|ts|tsx)?$',
  globals: {
    'ts-jest': {
      tsConfig: 'tsconfig.json',
    },
  },
  moduleFileExtensions: ['ts', 'js'],
  transform: {
    '^.+\\.(ts|tsx)$': 'ts-jest',
  },
  testEnvironment: 'node',
  reporters: [
    'default',
    [
      '../../node_modules/jest-html-reporter',
      {
        pageTitle: 'Unit Test Report',
        outputPath: 'tests/reports/unit-test-report.html',
        includeFailureMsg: true,
      },
    ],
  ],
  collectCoverage: true,
  collectCoverageFrom: [
    '../../api/**/*.ts'
  ],
  moduleFileExtensions: ["ts", "js", "json"], …
Run Code Online (Sandbox Code Playgroud)

javascript code-coverage node.js typescript jestjs

3
推荐指数
1
解决办法
5872
查看次数

如何使用 Jest 模拟 mailgun.messages().send() ?

我用的mailgun-js Api是发邮件。我编写了集成测试而不是单元测试。sendEmail现在我需要为类中包装的方法编写单元测试用例Mailgun。我不知道如何嘲笑mailgun.messages().send()。谁能帮我这个?

javascript node.js typescript jestjs

2
推荐指数
1
解决办法
2145
查看次数