2017-02-17 51 views
0

我想對從promise調用中獲得的結果進行一堆測試。我知道這是可以做到的:對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」/ unit測試,以便不同的測試用例實際顯示在輸出中?

回答

3

您應該能夠將它們組合在一起的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)); 

    // ... 
});