【问题标题】:Running multiple tests on Promise results - Mocha对 Promise 结果运行多个测试 - Mocha
【发布时间】:2017-07-06 14:34:30
【问题描述】:

我想对从 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),仅当所有预期条件都为真时才通过,并且这些预期部分不会显示在输出屏幕中。

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

【问题讨论】:

    标签: node.js unit-testing promise mocha.js chai


    【解决方案1】:

    您应该能够将它们组合在 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));
    
        // ...
    });
    

    【讨论】:

      猜你喜欢
      • 2017-04-08
      • 2015-02-17
      • 2017-01-10
      • 2016-09-21
      • 2015-01-21
      • 2015-07-16
      • 2018-12-02
      • 2020-08-26
      • 1970-01-01
      相关资源
      最近更新 更多