运行 对 Promise 结果的多项测试 - Mocha

Running multiple tests on Promise results - Mocha

我想要 运行 对从 promise 调用获得的结果进行一系列测试。我知道可以这样做:

it ('should pass test foo1', () => {
  return promisecall()
    .then(result => {
      expect(result.length).to.equal(42)
      expect(some other test on data)
      expect(some other test on data)
                .
                .
    })
})

根据我的理解,它的作用是: 运行单个测试(即应该通过测试 foo1),只有在所有预期条件都为真时才会通过,并且这些预期部分不会显示在输出屏幕中。

如何在单个承诺结果的结果上添加多个 'it' / 单元测试,以便不同的测试用例实际显示在输出中?

您应该能够将它们组合在 describe() 和 运行 中 before():

describe('things with promises', () => {
    var promiseResult;

    before(() => promiseCall().then(result => promiseResult = result));

    it ('should pass test foo1', () => expect(promiseResult.length).to.equal(42));

    it ('should pass test foo2', () => expect(some other test));

    // ...
});