簡體   English   中英

Mocha中“待定”測試意味着什么,我怎樣才能通過/失敗?

[英]What does 'pending' test mean in Mocha, and how can I make it pass/fail?

我正在運行我的測試並注意到:

18 passing (150ms)
1 pending

我以前沒見過這個。 以前測試要么通過要么失敗了。 超時導致失敗。 我可以看到哪個測試失敗了,因為它也是藍色的。 但它有一個超時。 這是一個簡化版本:

test(`Errors when bad thing happens`), function(){
  try {
    var actual = doThing(option)        
  } catch (err) {
    assert(err.message.includes('invalid'))
  }
  throw new Error(`Expected an error and didn't get one!`)
}
  • “待定”是什么意思? 當Mocha退出並且節點不再運行時,測試如何“掛起”?
  • 為什么這個測試沒有超時?
  • 如何使測試通過或失敗?

謝謝!

測試可以最終被所示摩卡為“待定”當你不經意間關閉了測試的it方法早,如:

// Incorrect -- arguments of the it method are closed early
it('tests some functionality'), () => {
  // Test code goes here...
};

it方法的參數應包括測試函數定義,如:

// Correct
it('tests some functionality', () => {
  // Test code goes here...
});

許多測試框架中的待測試是測試跑步者決定不運行。 有時這是因為測試被標記為跳過。 有時因為測試只是TODO的占位符。

對於Mocha, 文檔說暫掛測試是沒有任何回調的測試。

你確定你正在看好考試嗎?

測試有一個回調 (即一個實際的功能,沒有完成),但重構代碼解決了這個問題。 問題是如何運行期望錯誤的代碼:

test('Errors when bad thing happens', function() {
  var gotExpectedError = false;
  try {
    var actual = doThing(option)       
  } catch (err) {
    if ( err.message.includes('Invalid') ) {
      gotExpectedError = true
    }
  }
  if ( ! gotExpectedError ) {   
    throw new Error(`Expected an error and didn't get one!`)
  }
});

當我遇到這個問題時,掛起的錯誤就是當我用skip定義一個describe測試時,忘了刪除它,就像那樣:

describe.skip('padding test', function () {
   it('good test', function () {
       expect(true).to.equal(true);
   })
});

並且確實運行了它,我得到了輸出

Pending test 'good test'

當我在描述測試中刪除跳過標志時,它再次起作用..

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM