对Promise结果运行多个测试 - Mocha

jgr*_*gr0 0 unit-testing mocha.js node.js promise chai

我想对从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)
                .
                .
    })
})
Run Code Online (Sandbox Code Playgroud)

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

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

JLR*_*she 5

您应该能够将它们组合在一起并在以下方面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));

    // ...
});
Run Code Online (Sandbox Code Playgroud)