【问题标题】:how can i place multiple test-suits in a single test-suit using Jest and supertest?如何使用 Jest 和 supertest 将多个测试套件放置在单个测试套件中?
【发布时间】:2021-10-21 17:32:15
【问题描述】:

我创建了多个测试套件并希望它们在单个测试套件或单个描述测试块下运行。 我把它们放在...

describe('',()=>{  
  require('test-suite1.test.ts')
  require('test-suite2.test.ts')
  require('test-suite3.test.ts')
  ...
  ....
}

谁能给我建议任何其他方法来替换 require 并仍然在单个测试套件下运行所有​​测试?

【问题讨论】:

  • 这种require方式有什么问题?
  • @slideshowp2 使用这种方式我无法跟踪当前正在运行的测试套件,它会在所有测试套件结束时显示结果。

标签: javascript node.js jestjs supertest


【解决方案1】:

你的测试布局可以是这样的:

describe('All of the functions from this file', () => {
  describe('first function', () => {
    test('first function test one', () => {
      // ... tests for the first function
    });
    test('first function test two', () => {
      // ... tests for the first function
    });
    test('first function test three', () => {
      // ... tests for the first function
    });

  });
  describe('second function', () => {
    test('second function test one', () => {
      // ... tests for the second function
    });
    test('second function test two', () => {
      // ... tests for the second function
    });
    test('second function test three', () => {
      // ... tests for the second function
    });
  });
});

【讨论】:

  • 是的,它只是这样,但我在不同的文件中有不同的测试套件,我想从一个文件中访问,不想将所有代码放在一个文件中。
【解决方案2】:

我在寻找实现此目标的替代方法时偶然发现了这一点,但不妨分享我当前的解决方案。

// suitOne.js
export const suitOne = () =>
  describe('some functionality', () => {
    it('tests smth', () => ...
  }

// suitTwo.js
export const suitTwo = () =>
  describe('some other functionality', () => {
    it('tests smth else', () => ...
  }

// allSuits.spec.js
import { suitOne } from './suitOne.js'
import { suitTwo } from './suitTwo.js'

suitOne()
suitTwo()

测试套装必须同步运行。

【讨论】:

    猜你喜欢
    • 2017-05-26
    • 1970-01-01
    • 2019-11-24
    • 1970-01-01
    • 2020-01-24
    • 2022-01-24
    • 2017-04-20
    • 1970-01-01
    • 2019-07-31
    相关资源
    最近更新 更多